POPMUISE
2023-07-06 14:36:26
開玩笑地說,出于某種原因,你會(huì)得到類似的東西expected: "test"
received: serializes to the same string如果你這樣做.toContainEqualexpected: "test"
received: "test"這似乎只發(fā)生在將 mongoose 與 jest 一起使用時(shí),但我認(rèn)為問題與 uriEncoding 和解碼有關(guān)
1 回答
Cats萌萌
TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊
如果您正在測(cè)試請(qǐng)求的響應(yīng),請(qǐng)嘗試
expected = decodeURI(encodeURI("test"))
result = [...] // equals "test"
expect(result).toEqual(expected)
這也可能有效,但有時(shí)會(huì)因?yàn)?JSON 字符串解析而出現(xiàn)問題
expected = <some object>
result = <object that serializes to the same string>
expect(result.toString()).toEqual(expect.toString())
如果您只是將文檔的結(jié)果與對(duì)象或聚合的輸出進(jìn)行比較,請(qǐng)嘗試
expect(result).toEqual(expected)
添加回答
舉報(bào)
0/150
提交
取消
