Skip to content

Commit

Permalink
Add circular shape checking
Browse files Browse the repository at this point in the history
  • Loading branch information
mattphillips committed Mar 20, 2019
1 parent 32d742e commit ef47fa2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/expect/src/__tests__/utils.test.js
Expand Up @@ -241,6 +241,17 @@ describe('iterableEquality', () => {
).toBe(false);
});

test('returns true when given circular Set shape', () => {
const a1 = new Set();
const a2 = new Set();
a1.add(a2);
a2.add(a1);
const b = new Set();
b.add(b);

expect(iterableEquality(a1, b)).toBe(true);
});

test('returns true when given circular key in Map', () => {
const a = new Map();
a.set(a, 'a');
Expand Down
2 changes: 0 additions & 2 deletions packages/expect/src/utils.ts
Expand Up @@ -166,8 +166,6 @@ export const iterableEquality = (
// circular reference is not equal to non-circular one
if (aStack[length] === a) {
return bStack[length] === b;
} else if (bStack[length] === b) {
return false;
}
}
aStack.push(a);
Expand Down

0 comments on commit ef47fa2

Please sign in to comment.