QUnit.config.autostart
version added: 1.0.0.
Description
Control when the test run may start, e.g. after asynchronously loading test files with RequireJS, AMD, ES6 dynamic imports, or other means.
type | boolean |
---|---|
default | true |
In the browser, QUnit by default waits for all <script>
elements to finish loading (by means of the window load
event). When using the QUnit CLI, it waits until the specified files are imported.
Set this property to false
to instruct QUnit to wait longer, allowing you to load test files asynchronously. Remember to call QUnit.start()
once you’re ready for tests to begin running.
If you asynchronously load test files without disabling autostart, you may encounter this warning:
warning: Unexpected test after runEnd.
Examples
ESM Dynamic imports
This example uses the import() operator to dynamically load ECMAScript module (ESM) files.
<script src="../lib/qunit.js"></script>
<script type="module" src="tests.js"></script>
// tests.js
QUnit.config.autostart = false;
Promise.all([
import('./foo.js'),
import('./bar.js')
]).then(function () {
QUnit.start();
});
Loading with RequireJS
This example uses RequireJS to call a “require” function as defined by the AMD specification (Asynchronous Module Definition).
QUnit.config.autostart = false;
require(
[
'tests/testModule1',
'tests/testModule2'
],
function () {
QUnit.start();
}
);