javascript - Jest 收到 : serializes to the same string

标签 javascript node.js mongoose jestjs

出于某种原因,你会得到类似的东西

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/

相关文章:

javascript - 如何从网络客户端操作 OpenWRT 路由器上的 MySQL DB

javascript - 过滤循环内的对象不起作用

javascript - JS 正则表达式从文本区域中删除 "too much"

javascript - 在 Node.js 中使用 Tau-Prolog

node.js - Node.js 的单元测试

node.js - 如何在 Sequelize 中明智地分离字段状态?

node.js - 蒙戈错误。发现(不可变)字段 '_id' 已更改为 _id

javascript - 逗号十进制值的 vue 指令绑定(bind)值问题

mongodb - Mongoose 和独特的领域

javascript - mongoose 和 nodejs 的 mongodb 连接超时错误