Bud*_*dda 6 javascript unit-testing qunit
我使用QUnit进行JavaScript单元测试,已经进行了不少测试.他们中的大多数使用断言的方式:
ok(condition.isTrue());
Run Code Online (Sandbox Code Playgroud)
Visual Studio嵌入式测试系统(在"测试资源管理器"中)和"外部"QUnit引擎(通过单击"快速测试(单击运行)"调用的上下文菜单可以很好地运行这些测试)离开了QUnit测试).
但是如果我以另一种方式使用assert:
notOk(condition.isFalse());
Run Code Online (Sandbox Code Playgroud)
然后测试只在Visual Studio测试系统内运行,而尝试通过QUnit运行测试会产生以下错误:
Died on test #1 at http://localhost:64720/Tests.js:123:1: notOk is not defined
Source:
ReferenceError: notOk is not defined
at Object.<anonymous> (http://localhost:64720/Tests.js:129:5)
at Object.Test.run (http://localhost:64720/qunit.js:790:18)
at http://localhost:64720/qunit.js:877:10
at process (http://localhost:64720/qunit.js:593:24)
at http://localhost:64720/qunit.js:182:5
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况以及如何让QUnit正常运行"notOk"?
谢谢.
您是否面临与此处相同的问题:“未定义”:Ember-qunit 似乎没有导入?
解决方案是通过断言使用 notOk,如下所示:
test('it is not ok', function(assert) {
var some_value = false;
assert.notOk(some_value);
});
Run Code Online (Sandbox Code Playgroud)