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 equality of ImmutableJS Record #13055

Merged
merged 2 commits into from
Jul 24, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Fixes

- `[jest-worker]` When a process runs out of memory worker exits correctly and doesn't spin indefinitely ([#13054](https://github.com/facebook/jest/pull/13054))
- `[@jest/expect-utils]` Fix deep equality of ImmutableJS Record ([#13055](https://github.com/facebook/jest/pull/13055))

### Chore & Maintenance

Expand Down
9 changes: 8 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, OrderedSet} from 'immutable';
import {List, OrderedMap, OrderedSet, Record} from 'immutable';
import {stringify} from 'jest-matcher-utils';
import {
arrayBufferEquality,
Expand Down Expand Up @@ -537,6 +537,13 @@ describe('iterableEquality', () => {
const b = List(['newValue']).toOrderedSet();
expect(iterableEquality(a, b)).toBe(true);
});

test('returns true when given Immutable Record without an OwnerID', () => {
class TestRecord extends Record({dummy: ''}) {}
const a = new TestRecord().merge({dummy: 'data'});
const b = new TestRecord().set('dummy', 'data');
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 @@ -243,6 +243,7 @@ const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
const IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';

export function isImmutableUnorderedKeyed(maybeKeyed: any) {
return !!(
Expand Down Expand Up @@ -283,3 +284,10 @@ export function isImmutableOrderedSet(maybeSet: any) {
maybeSet[IS_ORDERED_SENTINEL]
);
}

export function isImmutableRecord(maybeSet: any) {
return !!(
maybeSet &&
maybeSet[IS_RECORD_SYMBOL]
);
}
4 changes: 3 additions & 1 deletion packages/expect-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isImmutableList,
isImmutableOrderedKeyed,
isImmutableOrderedSet,
isImmutableRecord,
isImmutableUnorderedKeyed,
isImmutableUnorderedSet,
} from './jasmineUtils';
Expand Down Expand Up @@ -260,7 +261,8 @@ export const iterableEquality = (
if (
!isImmutableList(a) &&
!isImmutableOrderedKeyed(a) &&
!isImmutableOrderedSet(a)
!isImmutableOrderedSet(a) &&
!isImmutableRecord(a)
) {
const aEntries = Object.entries(a);
const bEntries = Object.entries(b);
Expand Down