Last active
November 3, 2019 18:01
-
-
Save jamesseanwright/cf997824b9fd484eb4be4b85b1fd5bd1 to your computer and use it in GitHub Desktop.
Deep equality of iterables in Jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('deep iterable equality', () => { | |
it('should deeply compare iterables based upon their type', () => { | |
expect([1, 2, 3]).toEqual([1, 2, 3]); | |
expect([1, [2, 3]]).toEqual([1, [2, 3]]); | |
expect([1, 2, 3]).not.toEqual([3, 2, 1]); | |
expect(new Set()).toEqual(new Set()); | |
expect(new Set([1, 2, 3])).toEqual(new Set([1, 2, 3])); | |
expect(new Set([1, 2, 3])).toEqual(new Set([3, 2, 1])); | |
expect(new Set([1, [2, 3]])).toEqual(new Set([[2, 3], 1])); | |
expect(new Set([1, new Set([2, 3])])).toEqual(new Set([new Set([3, 2]), 1])); | |
expect(new Set([1, 2, 3])).not.toEqual(new Set([3, 1, 1])); | |
expect(new Map()).toEqual(new Map()); | |
expect(new Map([[1, 1], [2, 2], [3, 3]])).toEqual(new Map([[1, 1], [2, 2], [3, 3]])); | |
expect(new Map([[1, 1], [2, 2], [3, 3]])).toEqual(new Map([[2, 2], [1, 1], [3, 3]])); | |
expect(new Map([[{x: 1}, true]])).toEqual(new Map([[{x: 1}, true]])); | |
expect(new Map([[{x: 1}, true]])).not.toEqual(new Map([[{x: 2}, true]])); | |
expect(new Map([[1, 1], [2, 2], [3, 3]])).not.toEqual(new Map([[2, 2], [1, 1], [4, 4]])); | |
expect(new Uint8Array([1, 2, 3])).toEqual(new Uint8Array([1, 2, 3])); | |
expect(new Uint8Array([1, 2, 3])).not.toEqual(new Uint8Array([3, 2, 1])); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment