摩卡/柴期托.拋出不捕捉拋出的錯誤我有問題去拿柴氏的expect.to.throw在我的node.js應(yīng)用程序的測試中工作。測試在拋出的錯誤上一直失敗,但是如果我將測試用例包裝在TRY和CATCH中,并斷言捕獲的錯誤,它就能工作。是嗎?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();});失?。?9 passing (25ms)
1 failing
1) Model Base should throw an error if you try to get an undefined property:
Error: Property does not exist in model schema.
摩卡/柴期托.拋出不捕捉拋出的錯誤
暮色呼如
2019-07-05 13:37:38