Short description first: The test in the following snipped is never executed:
setTimeout(function() {
test("test", function() {
ok(true, "okay");
})
}, 1000);
Is there any way not to autostart the mocha-qunit-ui but wait for some asynchronous callbacks to create tests?
So, why would I need it this way?
I'm trying to run in-browser-tests for my classes with nodejs and the mocha-qunit-ui. The classes are loaded asynchrously by requirejs.
So I could create a test like this:
test("test", function() {
stop();
requirejs(
['Dependency'],
function(Dependency)
{
expect(1);
var d = new Dependency();
ok(d.test(), "test");
start();
}
);
}
But I want to run multiple tests on the same class with the same dependencies, so I thought of creating a test object
var d = new Dependency();
outside of the test. But then the test would be inside an asynchronous call, and therefore is never called.
Well, I'm not terribly familiar with mocha-qunit-ui plugin specifically, but QUnit has a config object that you can use to tell it not to run until you are ready (so you can load all of your classes, etc first):
<script src="path/to/qunit.js"></script>
<script>
QUnit.config.autostart = false; // be sure this is set BEFORE you add your actual tests
require(
[ "whatever", "your", "dependencies", "are" ],
function() {
QUnit.start(); // tell QUnit you're ready to go
}
);
<script>