我正在尝试为Jasmine测试框架编写测试,该测试期望出现错误.目前我正在使用GitHub的Jasmine Node.js集成.
在我的Node模块中,我有以下代码:
throw new Error("Parsing is not possible");
Run Code Online (Sandbox Code Playgroud)
现在我尝试编写一个期望这个错误的测试:
describe('my suite...', function() {
[..]
it('should not parse foo', function() {
[..]
expect(parser.parse(raw)).toThrow(new Error("Parsing is not possible"));
});
});
Run Code Online (Sandbox Code Playgroud)
我也试过了Error()
一些其他的变种,只是无法弄清楚如何使它工作.