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

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

    this does not answer the question exactly, but still may help people that end up here by google search:

    if you only care that a subset of the array has certain elements, use expect.arrayContaining() https://jestjs.io/docs/en/expect#expectarraycontainingarray

    e.g.,

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

提交回复
热议问题