我为我的项目使用主干样板并且在测试它时遇到了问题。对于测试,我使用 QUnit。例如,测试集合:
测试/index.html
<html>
<head>
...qunit.js, qunit.css, other libraries...
<script data-main="../../app/config" src="../../vendor/js/libs/require.js"></script>
<!-- Declare your test files to be run here -->
<script>
QUnit.config.autostart = false;
// Ensure you point to where your tests are, base directory is app/, which
// is why ../test is necessary
require({
paths: {
tests: "../test/qunit/tests"
}
}, [
// Load the example tests, replace this and add your own tests
// "tests/example",
"tests/sites/collections"
], QUnit.start);
</script>
</head>
</html>
测试/站点/collections.js
define(['modules/sites'], function (Sites) {
module("module sites collection", {
setup: function () {
this.collection = new Sites.Collection();
}
});
test("URL of sites collection.", function () {
expect(1);
equal(this.collection.url, 'http://bbb-example.x:8001/sites');
});
});
我在测试部分中的 grunt.js 文件如下所示:
qunit: {
all: ["test/qunit/*.html"]
},
当我打开浏览器窗口一切正常时,我看到了我的测试:
Tests completed in 385 milliseconds.
1 assertions of 1 passed, 0 failed.
但是当我尝试在控制台中运行它时,我看到了奇怪的错误:
~/projects/JS-bbb-example$ bbb test
Running "qunit:all" (qunit) task
Testing index.html
<WARN> PhantomJS timed out, possibly due to a missing QUnit start() call. Use --force to continue. </WARN>
Aborted due to warnings.
>> 0 assertions passed (0ms)
Done, but with warnings.
也许您知道这个问题并知道如何解决?感谢帮助。