Skip to content

Commit ef47fa2

Browse files
committed
Add circular shape checking
1 parent 32d742e commit ef47fa2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/expect/src/__tests__/utils.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,17 @@ describe('iterableEquality', () => {
241241
).toBe(false);
242242
});
243243

244+
test('returns true when given circular Set shape', () => {
245+
const a1 = new Set();
246+
const a2 = new Set();
247+
a1.add(a2);
248+
a2.add(a1);
249+
const b = new Set();
250+
b.add(b);
251+
252+
expect(iterableEquality(a1, b)).toBe(true);
253+
});
254+
244255
test('returns true when given circular key in Map', () => {
245256
const a = new Map();
246257
a.set(a, 'a');

packages/expect/src/utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ export const iterableEquality = (
166166
// circular reference is not equal to non-circular one
167167
if (aStack[length] === a) {
168168
return bStack[length] === b;
169-
} else if (bStack[length] === b) {
170-
return false;
171169
}
172170
}
173171
aStack.push(a);

0 commit comments

Comments
 (0)