Typically, each test environment allows you to run asynchronous tests and run tests manually, which should be what you need.
QUnit
For QUnit, you need to set the autostart parameter to false in order to activate the kick tests manually:
QUnit.config.autostart = false; require(['test/qunit/test.js'], function() { QUnit.start(); });
If you load things asynchronously during tests, just use the QUnits stop() and start() methods:
test('something that loads asynchronously', function() { stop(); define(['something'], function(sth) { ok(sth, 'Something loaded'); start(); }); });
Mocha
Mocha works very similarly:
mocha.setup('bdd'); require([ 'test/mocha/test.js' ], function() { mocha.run(); });
Asynchronous tests are even better by declaring a parameter that will be a callback for your specification:
describe('an async something', function() { it('loads the dependency', function(done) { define(['something'], function(sth) { ok(sth, 'Something loaded'); done(); }); }); });
That should work. It's one thing to keep in mind that tests may not always run in the same order if you download test files using RequireJS.
source share