小编use*_*756的帖子

了解QUnit异常测试

在编写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)

javascript testing exception qunit throws

5
推荐指数
1
解决办法
2492
查看次数

标签 统计

exception ×1

javascript ×1

qunit ×1

testing ×1

throws ×1