给出以下单元测试:
var object = {
a: [],
b: [],
c: null,
d: [],
e: []
};
describe('Multiple assertions', () => {
it("Should be all arrays", (done) => {
expect(object).to.have.property('a').that.is.a('array');
expect(object).to.have.property('b').that.is.a('array');
expect(object).to.have.property('c').that.is.a('array');
expect(object).to.have.property('d').that.is.a('array');
expect(object).to.have.property('e').that.is.a('array');
done();
});
});
它正确地失败了其中一个不是数组的属性,但是从输出中不清楚哪个属性导致测试失败:
1) Multiple assertions
Should be all arrays:
AssertionError: expected null to be an array
at Context.it (server/test/serverTest.js:27:48)
摩卡咖啡是否有可能打印出如下所示的更具描述性的输出?
For property 'c' expected null to be an array
您可以始终使用try {} catch {}
您的expect()
功能并自行格式化错误。但我不确定这是否是回答此问题的最佳方法。