Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a QUnit runner based on where the code runs: use the Node.js CLI for Node.js code, and the browser runner for DOM behavior or other code that needs a browser. Both start with the same essentials: group tests with QUnit.module(), define a case with QUnit.test(), and check a result through the assertion object.

Choose the runner that matches your code

Need Node.js CLI Browser runner
Best first use Modules and code executed under Node.js DOM behavior and code that needs a browser runtime
Setup Install the qunit package and add a test script Load QUnit’s JavaScript and CSS in an HTML test page
Feedback Results in the terminal; options include filtering and watch mode Results in the browser, with a fixture and filtering controls
Automation Run the CLI from scripts or CI; coverage tooling is optional Use a browser test integration such as Karma or Web Test Runner when it fits your build stack

These are two ways to run QUnit tests, not two different test APIs. QUnit describes itself as a JavaScript testing framework supporting Node.js, SpiderMonkey, and major browsers; its stated priorities include straightforward setup, testing in the code’s runtime, and extensibility. See the About page and API overview.

Write and run a first test in Node.js

For Node.js code, the CLI guide’s basic flow is to install QUnit locally, export a small function, and put a test under the default test directory.

  1. Install QUnit as a development dependency. Run npm install --save-dev qunit. With Yarn, use yarn add --dev qunit.
  2. Create the function under test. For example, save this as add.js: export function add(a, b) { return a + b; }. Match the export and import style to the module system your project uses.
  3. Create test/add.js. Import the function and write a small case:
    import QUnit from 'qunit';
    import { add } from '../add.js';
    
    QUnit.module('add');
    
    QUnit.test('two numbers', (assert) => {
      assert.equal(add(1, 2), 3);
    });
  4. Add the test command. In package.json, add "test": "qunit" under scripts, preserving any existing scripts.
  5. Run it. Execute npm test. QUnit reports results in the terminal in TAP-style output.

By default, the CLI searches for test/**/*.js. You can instead provide file names, directories, or glob expressions to run specific tests. The CLI documentation also covers --watch for rerunning tests after changes, --filter and --module for selecting a subset, reporters, --require for setup modules, and --seed for randomized test order. For an optional coverage workflow, it demonstrates nyc qunit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run a first test in a browser

Use the browser runner when the test needs browser APIs or the DOM. The test page needs QUnit’s JavaScript and stylesheet, plus two elements: one for results and one for test-owned DOM fixtures.

  1. Add the QUnit assets. Load qunit.js and qunit.css in an HTML page. For local or offline development, the browser guide recommends installing or downloading QUnit into the project rather than relying only on a CDN. Its example uses a QUnit 2.26.0 CDN URL; verify the current release and exact asset URL before using a CDN.
  2. Add the runner elements. Include <div id="qunit"></div> for the report and <div id="qunit-fixture"></div> for DOM content created by tests.
  3. Define a test. Add a script that uses QUnit.module() and QUnit.test(), then make assertions through the callback’s assert object. For example, a test can place a button in #qunit-fixture and check a DOM property or behavior.
  4. Open the page in a browser. The QUnit report appears in the page. Keep test-owned DOM changes inside #qunit-fixture; QUnit resets its markup after each test, helping isolate tests from one another.

For automated browser execution, the guide lists integrations including Karma, Web Test Runner, and Testem, among others. Choose one when it suits an existing build stack; none is required just to try a first test.

Understand when QUnit starts

In ordinary CLI and browser runs, QUnit starts automatically after the relevant test files or scripts load. You do not need to add QUnit.start() to each test file.

Manual startup is for a custom runner or asynchronous test loading. If AMD, RequireJS, dynamic imports, or another asynchronous loader registers tests, set QUnit.config.autostart = false before starting that loading process, then call QUnit.start() once all test files have been registered. Defining tests after the run has ended can trigger an “Unexpected test after runEnd” error. See the documentation for QUnit.config.autostart and QUnit.start().

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check version compatibility before setup

The QUnit homepage currently displays v2.26.0; that is the release indicator on the retrieved page, not a release date. The separate QUnit 3.0 upgrade guide says the QUnit 3 CLI requires Node.js 18 or later and removes support for Node.js 10–16 and PhantomJS. Those QUnit 3.0 compatibility notes should not be applied to every QUnit 2.x installation. Check the release and compatibility information for the major version you intend to use, because version details and support policies can change.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.