Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(expect-utils): Fix deep equality of ImmutableJS OrderedMaps #12899

Merged
merged 4 commits into from
Jun 2, 2022
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
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