Skip to content

Commit

Permalink
fix(expect-utils): Fix equalityof ImmutableJS OrderedSets (#12977)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbomb committed Jun 30, 2022
1 parent 93e1150 commit 0c37619
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion packages/expect-utils/src/__tests__/utils.test.ts
Expand Up @@ -6,7 +6,7 @@
*
*/

import {List, OrderedMap} from 'immutable';
import {List, OrderedMap, OrderedSet} from 'immutable';
import {stringify} from 'jest-matcher-utils';
import {
arrayBufferEquality,
Expand Down Expand Up @@ -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', () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/expect-utils/src/jasmineUtils.ts
Expand Up @@ -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]
);
}
7 changes: 6 additions & 1 deletion packages/expect-utils/src/utils.ts
Expand Up @@ -12,6 +12,7 @@ import {
isA,
isImmutableList,
isImmutableOrderedKeyed,
isImmutableOrderedSet,
isImmutableUnorderedKeyed,
isImmutableUnorderedSet,
} from './jasmineUtils';
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 0c37619

Please sign in to comment.