在编写QUnit测试时,我对'throws'的行为感到惊讶.关于以下代码(http://jsfiddle.net/DuYAc/75/),有谁可以回答我的问题:
function subfunc() {
throw "subfunc error";
}
function func() {
try {
subfunc();
} catch (e) {}
}
test("official cookbook example", function () {
throws(function () {
throw "error";
}, "Must throw error to pass.");
});
test("Would expect this to work", function () {
throws(subfunc(), "Must throw error to pass.");
});
test("Why do I need this encapsulation?", function () {
throws(function(){subfunc()}, "Must throw error to pass.");
});
test("Would expect this to fail, because func does not throw …Run Code Online (Sandbox Code Playgroud)