Skip to content

Commit f24ab2b

Browse files
authored
fix(expect-utils): Fix equality of ImmutableJS Record (#13055)
1 parent 837af9e commit f24ab2b

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Fixes
1010

1111
- `[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))
12+
- `[@jest/expect-utils]` Fix deep equality of ImmutableJS Record ([#13055](https://github.com/facebook/jest/pull/13055))
1213

1314
### Chore & Maintenance
1415

packages/expect-utils/src/__tests__/utils.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
import {List, OrderedMap, OrderedSet} from 'immutable';
9+
import {List, OrderedMap, OrderedSet, Record} from 'immutable';
1010
import {stringify} from 'jest-matcher-utils';
1111
import {
1212
arrayBufferEquality,
@@ -537,6 +537,13 @@ describe('iterableEquality', () => {
537537
const b = List(['newValue']).toOrderedSet();
538538
expect(iterableEquality(a, b)).toBe(true);
539539
});
540+
541+
test('returns true when given Immutable Record without an OwnerID', () => {
542+
class TestRecord extends Record({dummy: ''}) {}
543+
const a = new TestRecord().merge({dummy: 'data'});
544+
const b = new TestRecord().set('dummy', 'data');
545+
expect(iterableEquality(a, b)).toBe(true);
546+
});
540547
});
541548

542549
describe('arrayBufferEquality', () => {

packages/expect-utils/src/jasmineUtils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
243243
const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
244244
const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
245245
const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
246+
const IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
246247

247248
export function isImmutableUnorderedKeyed(maybeKeyed: any) {
248249
return !!(
@@ -283,3 +284,10 @@ export function isImmutableOrderedSet(maybeSet: any) {
283284
maybeSet[IS_ORDERED_SENTINEL]
284285
);
285286
}
287+
288+
export function isImmutableRecord(maybeSet: any) {
289+
return !!(
290+
maybeSet &&
291+
maybeSet[IS_RECORD_SYMBOL]
292+
);
293+
}

packages/expect-utils/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
isImmutableList,
1414
isImmutableOrderedKeyed,
1515
isImmutableOrderedSet,
16+
isImmutableRecord,
1617
isImmutableUnorderedKeyed,
1718
isImmutableUnorderedSet,
1819
} from './jasmineUtils';
@@ -260,7 +261,8 @@ export const iterableEquality = (
260261
if (
261262
!isImmutableList(a) &&
262263
!isImmutableOrderedKeyed(a) &&
263-
!isImmutableOrderedSet(a)
264+
!isImmutableOrderedSet(a) &&
265+
!isImmutableRecord(a)
264266
) {
265267
const aEntries = Object.entries(a);
266268
const bEntries = Object.entries(b);

0 commit comments

Comments
 (0)