-
-
Notifications
You must be signed in to change notification settings - Fork 224
Closed
Description
I was looking for a shortcut to check if an Array exactly matches the contents including order (but was not necessarily strictly equal). The matcher would have test cases like this:
describe('matchArray', () => {
it('matches arrays', () => {
expect(matchArray(['a', 'b'], ['a', 'b'])).toBeTruthy();
expect(matchArray(['a', 'b', 'c'], ['a', 'b'])).toBeFalsy();
expect(matchArray(['a', 'b'], ['a', 'b', 'c'])).toBeFalsy();
expect(matchArray(['a', 'b'], ['b', 'a'])).toBeFalsy();
});
it('short-circuits via equality', () => {
const a = [NaN]; // NaN === NaN returns false
expect(matchArray(a, a)).toBeTruthy();
});
it('uses strict equality', () => {
expect(matchArray(['1'], [1])).toBeFalsy();
expect(matchArray([{}], [{}])).toBeFalsy();
const a = {};
expect(matchArray([a], [a])).toBeTruthy();
});
});
I ended up writing this myself but would be happy to contribute it if you'll accept it.
vatosarmat, alexkirmse and sandinmyjoints
Metadata
Metadata
Assignees
Labels
No labels