Smaillns
Smaillns

Reputation: 3137

Jest test fail even the returned array values are correct

the expect returned values are the same but to test always fail, here the logged result

Error: expect(received).toContain(expected) // indexOf

Expected value: [72, 71]
Received array: [72, 71]

enter image description here

I will be gratefull for any explanation

Upvotes: 1

Views: 843

Answers (1)

Smaillns
Smaillns

Reputation: 3137

In fact I just found a quick solution using a correct jest matcher

Before

expect(c.users.map((u) => u.id)).toContain([72, 71]);

After

 expect(c.users.map((u) => u.id)).toEqual(expect.arrayContaining([72, 71]));

Upvotes: 2

Related Questions