vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Add matcher `toIncludeSameMembers`

Open SimonSimCity opened this issue 1 month ago • 0 comments

Clear and concise description of the problem

I often have a use-case for checking whether two arrays contain equal elements but in a different order.

Suggested solution

I found a PR for the jest-extended package, which includes an implementation of a matcher (https://github.com/jest-community/jest-extended/pull/122/files#diff-0bca30d1ed803269281ba667ea219217c02b44935f4b2391f987bd9d20ebf7d5)

There's an update request to this feature: https://github.com/jest-community/jest-extended/issues/639 and the author created a separate npm package, which also seems to work with vitest.

Alternative

  • Write a custom matcher
  • Search for some package which has this functionality
  • Add a sorting every time I want to compare two arrays this way
  • Install the npm package expect-matchers

Additional context

No response

Validations

SimonSimCity avatar Dec 10 '25 08:12 SimonSimCity