I've been really digging RequireJS, thanks for the great work James!
I was able to successfully run tests using the RequireJS approach, i.e., define a test module, with the code to be tested as explicit dependencies, and waiting to call start as described above. Async behavior is handled via QUnit.stop()/start() as described in the API:
define(
[
"my/moduletotest1",
"my/moduletotest2",
"my/moduletotest3",
],
function (moduletotest1, moduletotest2, moduletotest3) {
return {
RunTests: function () {
test("mod1test", function () {
QUnit.stop();
moduletotest1.ajaxyMethod(arg, function(result) {
deepEqual(result, matchExpression);
QUnit.start();
});
});
test("mod2test", function () {
QUnit.stop();
moduletotest2.ajaxyMethod(arg, function(result) {
equal(result, matchExpression);
QUnit.start();
});
});
...
}
};
});
Then in the QUnit page script:
QUnit.config.autostart = false;
require(
[
"UnitTests/TestModule",
],
function (testModule) {
QUnit.start();
testModule.RunTests();
}
);
Works like a charm!
Tim