我使用 jQuery 的 qUni 为我所做的一些 Bacon.js 函数编写了一些测试。
然而 Bacon.js 抛出一个错误,qUnit 将测试标记为失败,但结果是正确的,并且 equals() 方法工作正常。
我的问题是我可以让 qUnit 忽略某种类型的错误或来自源的错误吗?
错误是这样的:
“未捕获的类型错误:未定义不是函数
来源:..../static/js/libs/Bacon.js:62"
谢谢
最佳答案
在没有看到实际测试的情况下,很难确切地说出您需要如何构建测试,但如果抛出的Error
是预期行为,那么您可以使用QUnit's throws()
assertion确保这按预期发生:
QUnit.test("this should throw an error...", function(assert) {
assert.throws(
function() {
someFunctionThatThrowsAnError("maybe with a 'bad' arg versus good?");
},
/undefined is not a function/, // regex to match, any other Error fails the test
"Error should be thrown with invalid arguments"
);
});
关于javascript - QUnit 忽略源错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26530407/