我正在编写测试,以验证异步进程已写入mongo的内容,并且should.include存在验证是否包含记录的问题。为了简化它,我的投影只包含一个字段(ag_status),我从应该接收到以下错误:
1) Agriculture record should return at least one record with ag_status to true:
Uncaught AssertionError: expected [ { ag_status: true },
{ ag_status: true },
{ ag_status: true },
{ ag_status: true },
{ ag_status: true },
{ ag_status: true } ] to include an object equal to { ag_status: true }下面是调用should.include的代码部分。我试过猜,猜-模糊和猜-的东西,但没有一个工作(并没有给出详细的信息,应该),所以我现在卡住了。任何帮助都是非常感谢的。
it('Agriculture record should return at least one record with ag_status to true', function(done){
MobAgriculture.model.find({ time_id: "AYearAgo" }, {_id: 0, ag_status: 1 }, function(err, result) {
should.not.exist(err);
should.exist(result);
result.should.have.length(6);
console.log(result);
var level2 = { "ag_status" : true };
result.should.include(level2);
done();
});
});发布于 2013-08-01 05:11:47
我对should.js不是很熟悉,但我认为您应该使用includeEql,因为您希望验证数组中是否存在一个等于level2的对象,而不是level2本身是否存在。从他们的文档
包括(Obj) 断言给定的obj是通过indexOf()存在的,因此这适用于实现indexOf的字符串、数组或自定义对象。
includeEql(obj) 断言与给定obj相等的对象存在于Array中:
https://stackoverflow.com/questions/17985555
复制相似问题