-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(expect): fix
toEqual
and toMatchObject
with circular referenc…
…es (#5535)
- Loading branch information
Showing
3 changed files
with
73 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { describe, expect, test } from 'vitest' | ||
|
||
describe('circular equality', () => { | ||
test('object, set, map', () => { | ||
// https://github.com/vitest-dev/vitest/issues/5533 | ||
function gen() { | ||
const obj = { | ||
a: new Set<any>(), | ||
b: new Map<any, any>(), | ||
} | ||
obj.a.add(obj) | ||
obj.b.set('k', obj) | ||
return obj | ||
} | ||
expect(gen()).toEqual(gen()) | ||
expect(gen()).toMatchObject(gen()) | ||
}) | ||
|
||
test('object, set', () => { | ||
function gen() { | ||
const obj = { | ||
a: new Set<any>(), | ||
b: new Set<any>(), | ||
} | ||
obj.a.add(obj) | ||
obj.b.add(obj) | ||
return obj | ||
} | ||
expect(gen()).toEqual(gen()) | ||
expect(gen()).toMatchObject(gen()) | ||
}) | ||
|
||
test('array, set', () => { | ||
function gen() { | ||
const obj = [new Set<any>(), new Set<any>()] | ||
obj[0].add(obj) | ||
obj[1].add(obj) | ||
return obj | ||
} | ||
expect(gen()).toEqual(gen()) | ||
expect(gen()).toMatchObject(gen()) | ||
}) | ||
|
||
test('object, array', () => { | ||
// https://github.com/jestjs/jest/issues/14734 | ||
function gen() { | ||
const a: any = { | ||
v: 1, | ||
} | ||
const c1: any = { | ||
ref: [], | ||
} | ||
c1.ref.push(c1) | ||
a.ref = c1 | ||
return a | ||
} | ||
expect(gen()).toEqual(gen()) | ||
expect(gen()).toMatchObject(gen()) | ||
}) | ||
}) |