From 0c37619df5d297c61bdc75e033a825d3fc5774e9 Mon Sep 17 00:00:00 2001 From: Matt Parrish Date: Thu, 30 Jun 2022 05:12:49 -0600 Subject: [PATCH] fix(expect-utils): Fix equalityof ImmutableJS OrderedSets (#12977) --- CHANGELOG.md | 2 ++ packages/expect-utils/src/__tests__/utils.test.ts | 8 +++++++- packages/expect-utils/src/jasmineUtils.ts | 9 +++++++++ packages/expect-utils/src/utils.ts | 7 ++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85a901a4810c..f5e306f654f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[@jest/expect-utils]` Fix deep equality of ImmutableJS OrderedSets ([#12977](https://github.com/facebook/jest/pull/12977)) + ### Chore & Maintenance ### Performance diff --git a/packages/expect-utils/src/__tests__/utils.test.ts b/packages/expect-utils/src/__tests__/utils.test.ts index e94c72e5c191..f47aec654384 100644 --- a/packages/expect-utils/src/__tests__/utils.test.ts +++ b/packages/expect-utils/src/__tests__/utils.test.ts @@ -6,7 +6,7 @@ * */ -import {List, OrderedMap} from 'immutable'; +import {List, OrderedMap, OrderedSet} from 'immutable'; import {stringify} from 'jest-matcher-utils'; import { arrayBufferEquality, @@ -531,6 +531,12 @@ describe('iterableEquality', () => { const b = OrderedMap().merge({saving: true}); expect(iterableEquality(a, b)).toBe(true); }); + + test('returns true when given Immutable OrderedSets without an OwnerID', () => { + const a = OrderedSet().add('newValue'); + const b = List(['newValue']).toOrderedSet(); + expect(iterableEquality(a, b)).toBe(true); + }); }); describe('arrayBufferEquality', () => { diff --git a/packages/expect-utils/src/jasmineUtils.ts b/packages/expect-utils/src/jasmineUtils.ts index 6b003ed89569..16b0253a4f32 100644 --- a/packages/expect-utils/src/jasmineUtils.ts +++ b/packages/expect-utils/src/jasmineUtils.ts @@ -274,3 +274,12 @@ export function isImmutableOrderedKeyed(maybeKeyed: any) { maybeKeyed[IS_ORDERED_SENTINEL] ); } + + +export function isImmutableOrderedSet(maybeSet: any) { + return !!( + maybeSet && + maybeSet[IS_SET_SENTINEL] && + maybeSet[IS_ORDERED_SENTINEL] + ); +} diff --git a/packages/expect-utils/src/utils.ts b/packages/expect-utils/src/utils.ts index 684a184a6370..e4605426ae70 100644 --- a/packages/expect-utils/src/utils.ts +++ b/packages/expect-utils/src/utils.ts @@ -12,6 +12,7 @@ import { isA, isImmutableList, isImmutableOrderedKeyed, + isImmutableOrderedSet, isImmutableUnorderedKeyed, isImmutableUnorderedSet, } from './jasmineUtils'; @@ -256,7 +257,11 @@ export const iterableEquality = ( return false; } - if (!isImmutableList(a) && !isImmutableOrderedKeyed(a)) { + if ( + !isImmutableList(a) && + !isImmutableOrderedKeyed(a) && + !isImmutableOrderedSet(a) + ) { const aEntries = Object.entries(a); const bEntries = Object.entries(b); if (!equals(aEntries, bEntries)) {