3

Everything which I've searched is always without/ignoring order.
I want to compare 2 arrays with order.

expect([1, 2, 3].concat(4)).toEqualWithOrder([1, 2, 3, 4])

expect([{ value: 1}, { value: 2}, { value: 3 }].concat({ value: 4 })
.toEqualWithOrder([
  { value: 1 },
  { value: 2 },
  { value: 3 },
  { value: 4 },
])

How can I do that with Jest? Should we use JSON.stringify?

Danny
  • 883
  • 8
  • 33

1 Answers1

6

Just use the normal .toEqual method. It does require the items to appear in the same order.

Only to deviate from that you'd need a special method.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375