question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: .toMatchArray()

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
overlookmotelcommented, Feb 20, 2020

.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?

expect( [1, 2, 3] ).toIncludeAllMembersInOrder( [1, 2, 3] ) // => pass
expect( [3, 2, 1] ).toIncludeAllMembersInOrder( [1, 2, 3] ) // => fail

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.

0reactions
kara-rylicommented, Oct 27, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found