Feature Request: .toMatchArray()
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Feature Requests - SmartBear Community
Welcome to the ReadyAPI Feature Requests board! Here you can review submitted feature requests and vote up the ones you like! If you...
Read more >Latest Feature requests topics - Babylon.js Forum
Topic Replies Views Activity
About the Feature requests category 0 568 May 6, 2019
Implement color picking · performance , ray 1 26 December 23,...
Read more >See a Feature Request's Feedback in Savio
Want to see all the feedback, people, and accounts who asked for a feature? This is the page you're looking for.
Read more >Log your feature requests in the Ideation module
The Ideation module is a great way for users to directly input their requests, see comments back from other users or from the...
Read more >Feature Requests - Sendinblue Help Center
trackLink(). Guillermo de la Puente; 3 months ago. 0 votes 0 comments. I'd like a way for users to submit feature requests.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
.toIncludeAllMembers()
does what you want, I think, except it accepts the same items in different order.So maybe
.toIncludeAllMembersInOrder()
would be a good name for this?That would throw an error like “Expected list to have all of the following members in order”, rather than your implementation which will throw “expect(received).toBeTruthy()”, which is less clear.
I don’t have a way of telling, but I’d wager that when I opened this issue,
toEqual
didn’t behave the same way. Regardless, I think the example above is close enough for the use case I was looking for that it would make sense to add similar-yet-different matcher.