Skip to content

Commit

Permalink
fix(expect-utils): Fix equality of ImmutableJS Record (#13055)
Browse files Browse the repository at this point in the history
  • Loading branch information
sa2taka authored Jul 24, 2022
1 parent 837af9e commit f24ab2b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
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

0 comments on commit f24ab2b

Please sign in to comment.