1
0
Fork 0
mirror of synced 2024-07-04 14:01:27 +12:00

More verbose test code

This commit is contained in:
Adria Navarro 2024-01-23 19:40:31 +01:00
parent 108508db7e
commit 52fca8714d

View file

@ -40,6 +40,18 @@ function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
}
function tryParseJson(str) {
if (typeof str !== "string") {
return
}
try {
return JSON.parse(str.replace(/\'/g, '"'))
} catch (e) {
return
}
}
describe("manifest", () => {
describe("examples are valid", () => {
describe.each(Object.keys(examples))("%s", collection => {
@ -67,18 +79,15 @@ describe("manifest", () => {
let result = await processString(hbs, context)
// Trim 's
js = js.replace(/^\'|\'$/g, "")
try {
let parsedExpected
if (
Array.isArray((parsedExpected = JSON.parse(js.replace(/\'/g, '"'))))
) {
if ((parsedExpected = tryParseJson(js))) {
if (Array.isArray(parsedExpected)) {
if (typeof parsedExpected[0] === "object") {
js = JSON.stringify(parsedExpected)
} else {
js = parsedExpected.join(",")
}
}
} catch {}
}
result = result.replace(/ /g, " ")
expect(result).toEqual(js)
})