我有问题让Chai expect.to.throw
在我的node.js应用程序的测试中工作.测试在抛出错误时保持失败,但是如果我在try中包装测试用例并捕获并断言捕获的错误,则它可以工作.
难道expect.to.throw
不喜欢的工作,我认为它应该还是什么?
it('should throw an error if you try to get an undefined property', function (done) {
var params = { a: 'test', b: 'test', c: 'test' };
var model = new TestModel(MOCK_REQUEST, params);
// neither of these work
expect(model.get('z')).to.throw('Property does not exist in model schema.');
expect(model.get('z')).to.throw(new Error('Property does not exist in model schema.'));
// this works
try {
model.get('z');
}
catch(err) {
expect(err).to.eql(new Error('Property does not exist in model schema.'));
}
done();
});
Run Code Online (Sandbox Code Playgroud)
失败:
19 …
Run Code Online (Sandbox Code Playgroud)