Skip to content

Commit

Permalink
[expect] Add negative equality tests (#8260)
Browse files Browse the repository at this point in the history
* Add negative equality tests

* Add changelog entry
  • Loading branch information
mattphillips authored and scotthovestadt committed Apr 3, 2019
1 parent f88ae4b commit 96c19a6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@

### Fixes

- `[expect]` Add negative equality tests for iterables ([#8260](https://github.com/facebook/jest/pull/8260))
- `[jest-haste-map]` Resolve fs watcher EMFILE error ([#8258](https://github.com/facebook/jest/pull/8258))

### Chore & Maintenance
Expand Down
30 changes: 30 additions & 0 deletions packages/expect/src/__tests__/utils.test.js
Expand Up @@ -241,6 +241,36 @@ describe('iterableEquality', () => {
).toBe(false);
});

test('returns false when given inequal set within a set', () => {
expect(
iterableEquality(new Set([new Set([2])]), new Set([new Set([1, 2])])),
).toBe(false);
expect(
iterableEquality(new Set([new Set([2])]), new Set([new Set([1, 2])])),
).toBe(false);
});

test('returns false when given inequal map within a set', () => {
expect(
iterableEquality(
new Set([new Map([['a', 2]])]),
new Set([new Map([['a', 3]])]),
),
).toBe(false);
expect(
iterableEquality(new Set([new Set([2])]), new Set([new Set([1, 2])])),
).toBe(false);
});

test('returns false when given inequal set within a map', () => {
expect(
iterableEquality(
new Map([['one', new Set([2])]]),
new Map([['one', new Set([1, 2])]]),
),
).toBe(false);
});

test('returns true when given circular Set shape', () => {
const a1 = new Set();
const a2 = new Set();
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/utils.ts
Expand Up @@ -172,7 +172,7 @@ export const iterableEquality = (
bStack.push(b);

const iterableEqualityWithStack = (a: any, b: any) =>
iterableEquality(a, b, aStack, bStack);
iterableEquality(a, b, [...aStack], [...bStack]);

if (a.size !== undefined) {
if (a.size !== b.size) {
Expand Down

0 comments on commit 96c19a6

Please sign in to comment.