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 equalityof ImmutableJS OrderedSets #12977

Merged
merged 2 commits into from Jun 30, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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