我目前正在使用Mocha和断言库should.js。
我正在尝试处理单元测试中抛出异常的情况--但是从文档来看,到目前为止我还没有太多的运气让它工作。
下面这段代码就是我目前使用的代码:
it('Adds a new employee to the db - FAILS', funct
let employeeObj = {
"Title": "Mr",
"FirstName": "Keanu ",
"LastName": "Reeves",
"Username": "KeanuReeves2",
"Password": "Password",
"Email": "keanu@reeves.com",
"IsActive": true
};
should(function () {
db.AddNewEmployee(employeeObj);
}).throw("U wot m8");
done();
}); 我一直收到这个错误:
AssertionError: expected Function { name: '' } to throw exception
at Assertion.fail (node_modules\should\cjs\should.js:275:17)
at Assertion.value (node_modules\should\cjs\should.js:356:19)
at Context.<anonymous> (common\spec\knexDBServiceSpec.js:213:25)有没有人有这个问题,或者能够给我一些指导,告诉我哪里出了问题?
发布于 2019-07-03 20:41:33
它所做的就是你设置它的目的。
你告诉应该,你的函数应该抛出一个异常"U wot m8“。但它没有,因此应该失败。
期望(应该)是它应该抛出。
https://stackoverflow.com/questions/56870266
复制相似问题