Is there an Array equality match function that ignores element position in jest.js?

前端 未结 6 1767
栀梦
栀梦 2021-02-06 20:06

I get that .toEqual() checks equality of all fields for plain objects:

expect(
    {"key1":"pin         


        
6条回答
  •  孤独总比滥情好
    2021-02-06 20:40

    There is no built-in method to compare arrays without comparing the order, but you can simply sort the arrays using .sort() before making a comparison:

    expect(["ping wool", "diorite"].sort()).toEqual(["diorite", "pink wool"].sort());
    

    You can check the example in this fiddle.

提交回复
热议问题