猿问

收到笑话:序列化为同一字符串

开玩笑地说,出于某种原因,你会得到类似的东西

expected: "test"
received: serializes to the same string

如果你这样做.toContainEqual

expected: "test"
received: "test"

这似乎只发生在将 mongoose 与 jest 一起使用时,但我认为问题与 uriEncoding 和解码有关


POPMUISE
浏览 154回答 1
1回答

Cats萌萌

如果您正在测试请求的响应,请尝试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)
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答