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

前端 未结 6 1763
栀梦
栀梦 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:51

    You can combine using sets as stated in this answer with checking length of actual result and expectation. This will ignore element position and protect you from duplicated elements in the same time.

    expect(
      new Set(['pink wool', 'diorite'])
    ).toEqual(
      new Set(['diorite', 'pink wool'])
    );
    

提交回复
热议问题