In jest for some reason you get something like
expected: "test"
received: serializes to the same string
if you do .toContainEqual
expected: "test"
received: "test"
this seems to only occur when using mongoose with jest, but I think the issue has to do with uriEncoding and decoding
If you're testing the response from a request then try
expected = decodeURI(encodeURI("test"))
result = [...] // equals "test"
expect(result).toEqual(expected)
This may also work but sometimes has issues because of JSON string parsing
expected = <some object>
result = <object that serializes to the same string>
expect(result.toString()).toEqual(expect.toString())
If you're only comparing the result of a document versus an object or output from an aggregation then try
expect(result).toEqual(expected)
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