【问题标题】:Using shouldjs to check values in an unordered array使用 shouldjs 检查无序数组中的值
【发布时间】:2014-12-12 10:04:41
【问题描述】:

我有一个 express.js 应用程序,我在其中使用 supertest 和 should.js 作为我的测试框架。我在测试无序数组中的值时遇到问题。

According to the should.js documentation, the .any function would work here. 任何关于如何让它工作的想法将不胜感激。

预期响应

{data: [
  {username:"Test User 3", ...},
  {username:"Test User 6", ...}
]}

尝试的验证调用

response.body.data.any.username.should.equal("Test User 3");
response.body.data.any.username.should.equal("Test User 6");

提前感谢您的帮助!

【问题讨论】:

    标签: javascript node.js testing express should.js


    【解决方案1】:

    containDeep怎么样:

    response.body.data.should.containDeep([{ username: "Test User 3" }]);
    response.body.data.should.containDeep([{ username: "Test User 6" }]);
    

    【讨论】:

    • 嘿蒂姆,感谢您的指点。我认为您在对象周围缺少数组括号。所以它应该是: response.body.data.should.containDeep([{ username: "Test User 3" }]);如果您不介意更新,我可以接受您的回答:)
    • 没错!已更新。
    猜你喜欢
    • 1970-01-01
    • 2013-10-23
    • 1970-01-01
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 2022-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多