How do I compare two collections in Jest ignoring element order?
问题 When writing a unit test in Jest, how can I test that an array contains exactly the expected values in any order ? In Chai , I can write: const value = [1, 2, 3]; expect(value).to.have.members([2, 1, 3]); What's the equivalent syntax in Jest? 回答1: Another way is to use the custom matcher .toIncludeSameMembers() from jest-community/jest-extended. Example given from the README test('passes when arrays match in a different order', () => { expect([1, 2, 3]).toIncludeSameMembers([3, 1, 2]); expect