相关疑难解决方法(0)

断言函数抛出Qunit的异常

我是Qunit和单元测试的新手.

我试图找出测试以下功能的内容和方法.它目前没有做太多但我想断言如果我传递错误值的错误值:

function attrToggle (panel, attr) {
    'use strict';

    if (!panel) { throw new Error('Panel is not defined'); }
    if (!attr) { throw new Error('Attr is not defined'); }
    if (typeof panel !== 'string') { throw new Error('Panel is not a string'); }
    if (typeof attr !== 'string') { throw new Error('Attr is not a string'); }
    if (arguments.length !== 2) { throw new Error('There should be only two arguments passed to this function')}

};
Run Code Online (Sandbox Code Playgroud)

如果不满足任何这些条件,我该怎么断言会抛出错误?

我试着看看Qunit的'加注'断言但认为我误解了它.我的解释是,如果抛出错误,测试就会通过.

所以,如果我测试了这样的东西:

test("a test", …
Run Code Online (Sandbox Code Playgroud)

javascript jquery unit-testing qunit

10
推荐指数
1
解决办法
4974
查看次数

标签 统计

javascript ×1

jquery ×1

qunit ×1

unit-testing ×1