Preparation Code Preparation HTML (this will be inserted in the <body>
of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries)
Setup JS const mixinQuery = {
a : '12345' ,
b : '23456' ,
c : '34567' ,
d : '45678' ,
e : 1234567890
}
const sortedParams = Object .keys (mixinQuery).sort ()
const charRegex = /[!'\(\)*]/g
Teardown JS
Test cases
Test #1 Title *
Async
Code * const mixinParams = []
for (var i = 0 ; i < sortedParams.length ; i++) {
var key = sortedParams[i]
var value = mixinQuery[key]
if (value && typeof value === 'string' ) {
value = value.replace (charRegex, '' )
}
if (value != null ) {
mixinParams.push ("" .concat (key, "=" ).concat (value))
}
}
Test #2 Title *
Async
Code * const mixinParams = []
sortedParams.forEach (element => {
const key = element
let value = mixinQuery[key]
if (value && typeof value === 'string' ) {
value = value.replace (charRegex, '' )
}
if (value !== null ) {
mixinParams.push (`${key} =${value} ` )
}
})
Title *
Async
Code * const mixinParams = sortedParams
.map (key => {
let value = mixinQuery[key]
if (value && typeof value === 'string' ) {
value = value.replace (charRegex, '' )
}
return value !== null ? `${key} =${value} ` : null
})
.filter (value => {
return value !== null
})
Title *
Async
Code * const mixinParams = sortedParams
.map (key => {
const value = mixinQuery[key]
if (value && typeof value === 'string' ) {
return `${key} =${value.replace(charRegex, '' )} `
}
return value !== undefined ? `${key} =${value} ` : value
})
.filter (value => {
return value !== undefined
})
Title *
Async
Code * const mixinParams = sortedParams.map (key => {
const value = mixinQuery[key]
if (typeof value === 'string' ) {
return `${key} =${value.replace(charRegex, '' )} `
}
return `${key} =${value} `
})
Title *
Async
Code * const mixinParams = sortedParams.map ((key ) => {
const value = mixinQuery[key].toString ().replace (charRegex, "" )
return `${key} =${value} `
})