use bun's equal check
This commit is contained in:
parent
c3453fdc5c
commit
e95c0d6728
|
|
@ -108,16 +108,10 @@ expect.extend({
|
|||
if (expected instanceof RegExp) expected = String(expected)
|
||||
if (value instanceof RegExp) value = String(value)
|
||||
|
||||
if (isEqual(value, expected)) {
|
||||
return { pass: true }
|
||||
} else {
|
||||
return {
|
||||
message: () =>
|
||||
`Expected evaluation to be ${JSON.stringify(expected)}, but got ${JSON.stringify(
|
||||
value
|
||||
)}`,
|
||||
pass: false,
|
||||
}
|
||||
expect(value).toEqual(expected)
|
||||
return {
|
||||
message: () => `Expected evaluation to be ${expected}, but got ${value}`,
|
||||
pass: true,
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
|
|
@ -167,29 +161,3 @@ const trimWhitespace = (str: string): string => {
|
|||
})
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
function isEqual(a: any, b: any): boolean {
|
||||
if (a === null && b === null) return true
|
||||
|
||||
switch (typeof a) {
|
||||
case 'string':
|
||||
case 'number':
|
||||
case 'boolean':
|
||||
case 'undefined':
|
||||
return a === b
|
||||
default:
|
||||
return JSON.stringify(sortKeys(a)) === JSON.stringify(sortKeys(b))
|
||||
}
|
||||
}
|
||||
|
||||
function sortKeys(o: any): any {
|
||||
if (Array.isArray(o)) return o.map(sortKeys)
|
||||
if (o && typeof o === 'object' && o.constructor === Object)
|
||||
return Object.keys(o)
|
||||
.sort()
|
||||
.reduce((r, k) => {
|
||||
r[k] = sortKeys(o[k])
|
||||
return r
|
||||
}, {} as any)
|
||||
return o
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user