在开玩笑的时候,出于某种原因,你会得到这样的结果:
expected: "test"
received: serializes to the same string
如果你使用.toContainEqual
expected: "test"
received: "test"
这似乎只有在使用mongoose和jest时才会发生,但我认为问题与uriEncoding和解码有关
发布于 2020-11-03 04:23:03
如果您正在测试来自请求的响应,请尝试
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)
https://stackoverflow.com/questions/64652777
复制相似问题