I created unit (async) test in Jest. But when I get response from server:
[
{
name: "My name"
},
{
name: "Another name"
}
]
and test it:
test('Response from server', () => {
get('my-url').end(error, response) => {
expect(response.body).toBe(expect.any(Array))
}
})
some error occurs:
Comparing two different types of values. Expected Array but received array.
It's working when I use expect(response.body).any(Array)
. But is there any fix for expect.toBe()
?
You should use toEqual
(not toBe
) to compare objects and arrays. Use toBe
for scalar data types only. If you like to check the response data type use typeof
operator
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With