出于某种原因,你会得到类似的东西
expected: "test"
received: serializes to the same string
如果你做 .toContainEqual
expected: "test"
received: "test"
这似乎只在将 Mongoose 与 jest 一起使用时才会发生,但我认为问题与 uriEncoding 和解码有关
最佳答案
如果您正在测试请求的响应,请尝试
expected = decodeURI(encodeURI("test"))
result = [...] // equals "test"
expect(result).toEqual(expected)
这也可能有效,但有时会因为 JSON 字符串解析而出现问题
expected = <some object>
result = <object that serializes to the same string>
expect(result.toString()).toEqual(expect.toString())
如果您只是将文档的结果与对象或聚合的输出进行比较,请尝试
expect(result).toEqual(expected)
关于javascript - Jest 收到 : serializes to the same string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64652777/