【发布时间】:2011-05-07 21:05:06
【问题描述】:
我正在尝试为 Jasmine Test Framework 编写一个测试,它预计会出错。目前我使用的是Jasmine Node.js integration from GitHub。
在我的 Node.js 模块中,我有以下代码:
throw new Error("Parsing is not possible");
现在我尝试编写一个预期此错误的测试:
describe('my suite...', function() {
[..]
it('should not parse foo', function() {
[..]
expect(parser.parse(raw)).toThrow(new Error("Parsing is not possible"));
});
});
我也尝试了Error() 和其他一些变体,但不知道如何使它工作。
【问题讨论】:
-
要将参数传递给正在测试的函数,而不使用匿名函数,请尝试
Function.bind:stackoverflow.com/a/13233194/294855
标签: javascript testing node.js jasmine