【发布时间】:2019-11-07 17:42:51
【问题描述】:
我正在使用 mocha 和 chai 进行测试。 res.body.data 是一个对象数组。
当我通过to.include 直接检查一个数组项时,它工作正常,但是当我尝试通过to.deep.include 检查整个数组时它失败了。
我卡住了,请帮忙!
res.body.data = [{
createdAt: 1573147796,
id: "36d337d4-0184-11ea-acb9-0e4ed9667580",
message: "Good",
name: "John Doe",
rate: 5
}]
//Running test
expect(res.body.data).to.be.an('array');
expect(res.body.data[0]).to.include({ //This works fine!
message: "Good"
});
expect(res.body.data).to.deep.include({ //But this trows an error
message: "Good"
});
//Uncaught AssertionError: expected [ Array(1) ] to deep include { message: 'Good' }
done();
【问题讨论】:
标签: javascript node.js testing mocha.js chai