Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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