Last active
November 3, 2019 21:30
-
-
Save jamesseanwright/017c72f54b2349578607fefb253c45be to your computer and use it in GitHub Desktop.
Deep equality of iterables with Chai
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
import { expect as chaiExpect } from 'chai'; | |
describe('deep iterable equality', () => { | |
it('should deeply compare iterables based upon their type', () => { | |
chaiExpect([1, 2, 3]).to.eql([1, 2, 3]); | |
chaiExpect([1, [2, 3]]).to.eql([1, [2, 3]]); | |
chaiExpect([1, 2, 3]).not.to.eql([3, 2, 1]); | |
chaiExpect(new Set()).to.eql(new Set()); | |
chaiExpect(new Set([1, 2, 3])).to.eql(new Set([1, 2, 3])); | |
chaiExpect(new Set([1, 2, 3])).to.eql(new Set([3, 2, 1])); | |
chaiExpect(new Set([1, [2, 3]])).to.eql(new Set([[2, 3], 1])); | |
chaiExpect(new Set([1, new Set([2, 3])])).to.eql(new Set([new Set([3, 2]), 1])); | |
chaiExpect(new Set([1, 2, 3])).not.to.eql(new Set([3, 1, 1])); | |
chaiExpect(new Map()).to.eql(new Map()); | |
chaiExpect(new Map([[1, 1], [2, 2], [3, 3]])).to.eql(new Map([[1, 1], [2, 2], [3, 3]])); | |
chaiExpect(new Map([[1, 1], [2, 2], [3, 3]])).to.eql(new Map([[2, 2], [1, 1], [3, 3]])); | |
chaiExpect(new Map([[{x: 1}, true]])).to.eql(new Map([[{x: 1}, true]])); | |
chaiExpect(new Map([[{x: 1}, true]])).not.to.eql(new Map([[{x: 2}, true]])); | |
chaiExpect(new Map([[1, 1], [2, 2], [3, 3]])).not.to.eql(new Map([[2, 2], [1, 1], [4, 4]])); | |
chaiExpect(new Uint8Array([1, 2, 3])).to.eql(new Uint8Array([1, 2, 3])); | |
chaiExpect(new Uint8Array([1, 2, 3])).not.to.eql(new Uint8Array([3, 2, 1])); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment