Skip to content

Commit

Permalink
Fixes ImmutableList case and adds test
Browse files Browse the repository at this point in the history
  • Loading branch information
romellem committed Apr 29, 2022
1 parent f3586a7 commit b40ef0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions packages/expect-utils/src/__tests__/utils.test.ts
Expand Up @@ -6,6 +6,7 @@
*
*/

import {List} from 'immutable';
import {stringify} from 'jest-matcher-utils';
import {
arrayBufferEquality,
Expand Down Expand Up @@ -517,6 +518,13 @@ describe('iterableEquality', () => {

expect(iterableEquality(a, b)).toBe(true);
});

test('returns true when given Immutable Lists without an OwnerID', () => {
const a = List([1, 2, 3]);
const b = a.filter(v => v > 0);

expect(iterableEquality(a, b)).toBe(true);
});
});

describe('arrayBufferEquality', () => {
Expand Down
11 changes: 6 additions & 5 deletions packages/expect-utils/src/utils.ts
Expand Up @@ -181,11 +181,7 @@ export const iterableEquality = (
if (a.size !== undefined) {
if (a.size !== b.size) {
return false;
} else if (
isA('Set', a) ||
isImmutableUnorderedSet(a) ||
isImmutableList(a)
) {
} else if (isA('Set', a) || isImmutableUnorderedSet(a)) {
let allFound = true;
for (const aValue of a) {
if (!b.has(aValue)) {
Expand Down Expand Up @@ -259,6 +255,11 @@ export const iterableEquality = (
return false;
}

if (isImmutableList(a)) {
// After iteration, Immutable Lists are equal
return true;
}

const aEntries = Object.entries(a);
const bEntries = Object.entries(b);
if (!equals(aEntries, bEntries)) {
Expand Down

0 comments on commit b40ef0b

Please sign in to comment.