Prelude of builtin functions #7
|
|
@ -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)
|
||||
|
defunkt marked this conversation as resolved
Outdated
|
||||
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
I rewrote this in the branch I'm on too!
If you replace this line with
You get to lean on bun's type checking code and you get all the nice diff support.
Awesome. Done.