[英]How to test if parameterized method throws chai and mocha?
I have this (simplified) code to test: 我有以下(简化)代码进行测试:
function verifyArg(x) {
if (x == 400) throw new Error("Bad Parameter!")
}
How do I test if the error is thrown correctly with mocha and chai? 我如何测试摩卡和柴是否正确引发了错误?
I found the answer myself: 我自己找到了答案:
describe("verify()", function() {
it("throws on 400", function() {
expect(function() {
verify(400);
}).not.to.throw();
});
});
callback hell ftw! 回调地狱!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.