Skip to content

Commit

Permalink
fix(expect-utils): Fix deep equality of ImmutableJS OrderedMaps (#12899)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbomb authored Jun 2, 2022
1 parent fb51581 commit 8f7f131
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

### Fixes

- `[jest-worker]` Make `JestWorkerFarm` helper type to include methods of worker module that take more than one argument ([#12839](https://github.com/facebook/jest/pull/12839))
- `[@jest/expect-utils]` Fix deep equality of ImmutableJS OrderedMaps ([#12763](https://github.com/facebook/jest/pull/12899))
- `[jest-docblock]` Handle multiline comments in parseWithComments ([#12845](https://github.com/facebook/jest/pull/12845))
- `[jest-worker]` Make `JestWorkerFarm` helper type to include methods of worker module that take more than one argument ([#12839](https://github.com/facebook/jest/pull/12839))

### Chore & Maintenance

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} from 'immutable';
import {List, OrderedMap} from 'immutable';
import {stringify} from 'jest-matcher-utils';
import {
arrayBufferEquality,
Expand Down Expand Up @@ -525,6 +525,12 @@ describe('iterableEquality', () => {

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

test('returns true when given Immutable OrderedMaps without an OwnerID', () => {
const a = OrderedMap().set('saving', true);
const b = OrderedMap().merge({saving: true});
expect(iterableEquality(a, b)).toBe(true);
});
});

describe('arrayBufferEquality', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/expect-utils/src/jasmineUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,11 @@ export function isImmutableList(maybeList: any) {
maybeList[IS_LIST_SENTINEL]
);
}

export function isImmutableOrderedKeyed(maybeKeyed: any) {
return !!(
maybeKeyed &&
maybeKeyed[IS_KEYED_SENTINEL] &&
maybeKeyed[IS_ORDERED_SENTINEL]
);
}
3 changes: 2 additions & 1 deletion packages/expect-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
equals,
isA,
isImmutableList,
isImmutableOrderedKeyed,
isImmutableUnorderedKeyed,
isImmutableUnorderedSet,
} from './jasmineUtils';
Expand Down Expand Up @@ -255,7 +256,7 @@ export const iterableEquality = (
return false;
}

if (!isImmutableList(a)) {
if (!isImmutableList(a) && !isImmutableOrderedKeyed(a)) {
const aEntries = Object.entries(a);
const bEntries = Object.entries(b);
if (!equals(aEntries, bEntries)) {
Expand Down

0 comments on commit 8f7f131

Please sign in to comment.