From ef47fa26f550b904d1f5515d74219434205708ab Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Wed, 20 Mar 2019 10:00:33 +0000 Subject: [PATCH] Add circular shape checking --- packages/expect/src/__tests__/utils.test.js | 11 +++++++++++ packages/expect/src/utils.ts | 2 -- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/expect/src/__tests__/utils.test.js b/packages/expect/src/__tests__/utils.test.js index b91634157858..7ff609a8ab87 100644 --- a/packages/expect/src/__tests__/utils.test.js +++ b/packages/expect/src/__tests__/utils.test.js @@ -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'); diff --git a/packages/expect/src/utils.ts b/packages/expect/src/utils.ts index 245f227701cf..749b20ec597d 100644 --- a/packages/expect/src/utils.ts +++ b/packages/expect/src/utils.ts @@ -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);