Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
120
rated 0 times [  122] [ 2]  / answers: 1 / hits: 12986  / 4 Years ago, mon, november 2, 2020, 12:00:00

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


More From » node.js

 Answers
11

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)

[#2378] Wednesday, October 28, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonrened

Total Points: 627
Total Questions: 114
Total Answers: 99

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
jonrened questions
Tue, May 19, 20, 00:00, 4 Years ago
Tue, Jan 21, 20, 00:00, 4 Years ago
Thu, Nov 7, 19, 00:00, 5 Years ago
Mon, Aug 26, 19, 00:00, 5 Years ago
;