Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
layout title amethyst redirect_from
Getting Started

The following guide will get you up-and-running with QUnit either [in Node.js](#in-nodejs) or [in the Browser](#in-the-browser).

In Node.js

Getting started with QUnit for Node.js projects is quick and easy. First, install the qunit package using npm:

npm install --save-dev qunit

# Or, if using Yarn:
yarn add --dev qunit

Let's create an example program that we can test! We'll start with a function that adds two numbers. Create a file add.js with the following contents:

function add(a, b) {
  return a + b;

module.exports = add;

Now, let's start writing tests! Create a file in a test directory, for example test/add.js, and write the following:

const add = require('../add.js');


QUnit.test('two numbers', assert => {
  assert.equal(add(1, 2), 3);

This defines a test suite for the "add" feature, with a single test case that verifies the result of adding two numbers together.

You can now run the test suite through the QUnit CLI. It is recommended that you run the qunit command via an npm script, which will find the qunit command automatically from your local dependencies. In your package.json file, specify it like so:

  "scripts": {
    "test": "qunit"

Then, simply run:

npm test

And QUnit will run your test!

TAP version 13
ok 1 add > two numbers
# pass 1
# skip 0
# todo 0
# fail 0

Congrats! You just wrote and executed your first QUnit test!

Check out the API documentation to learn more about the QUnit APIs for organising tests and making assertions.

See Command-line interface for help with the qunit command.

Support policy

QUnit follows the Node.js Long-term Support (LTS) schedule and provides support for Current, Active LTS, and Maintenance LTS releases.

Package name prior to 2.4.1

Prior to QUnit 2.4.1, the npm package was published under the name "qunitjs" instead of "qunit". To install earlier versions of QUnit for Node, check out qunitjs.

The 0.x and 1.x versions of the "qunit" package on npm holds an alternative CLI that is now published as node-qunit.


The eslint-plugin-qunit package has a variety of rules available for enforcing best testing practices as well as detecting broken tests.

In the Browser

To get started with QUnit in the browser, create a simple HTML file called test.html and include the following markup:

<!DOCTYPE html>
<meta charset="utf-8">
<title>Test Suite</title>
<link rel="stylesheet" href="">
  <div id="qunit"></div>
  <div id="qunit-fixture"></div>
  <script src=""></script>

That's all the markup you need to start writing tests. Note that this loads the library from the jQuery CDN.

See also Integrations & Downloads for integration you can use to automate browser testing. These usually also manage the HTML file for you.

Let's add the following script, which tests an example add() function for adding two numbers together:

  function add(a, b) {
    return a + b;

  QUnit.module('add', function() {
    QUnit.test('two numbers', function(assert) {
      assert.equal(add(1, 2), 3);

This code defines a test module for the add() function and verifies the result of adding two numbers.

If you open this up in the browser you'll find a detailed report of the tests that ran and their assertions, as well as various options for filtering and re-running individual tests to help during development. Like so:

<iframe loading="lazy" title="The test code running in the browser" src="/resources/example-index.html" style="height: 300px;"></iframe>

Congrats! You just wrote and executed your first QUnit test!

Check out the API documentation to learn more about the QUnit APIs for organising tests and making assertions.

Browser support

QUnit currently supports the following browsers:

  • Internet Explorer: 9+
  • Edge: 15+ (both legacy MSEdge and Chromium-based)
  • Firefox: 45+
  • Safari: 9+
  • Opera: 36+
  • Chrome: 58+
  • Android: 4.3+
  • iOS: 7+ (Mobile Safari)

For older browsers, such as Internet Explorer 6-8, Opera 12+, or Safari 5+, please use the 1.x series of QUnit.


The following integrations can be used to automate the running of browser tests with QUnit:

Example projects:

  • Krinkle/example-node-and-browser-qunit-ci: Run QUnit tests locally and in CI, on Headless Firefox and Chrome (using Karma), and with Node.js.
    Also demonstrates code coverage, and testing of isomorphic JavaScript projects.

Release channels

These are the officially supported download channels for QUnit releases:

  • Download:

    QUnit has no runtime dependencies for browser use. You can save the qunit-2.19.4.js and qunit-2.19.4.css files directly from the jQuery CDN, which is powered by StackPath.

    Or download them via the terminal:

    curl -o qunit.css ''
    curl -o qunit.js ''
  • npm Registry:

    If your development workflow uses Node.js, you can install the qunit package the npm Registry, using the npm CLI:

    npm install --save-dev qunit

    Or, if using Yarn:

    yarn add --dev qunit

    You can then reference node_modules/qunit/qunit/qunit.css and node_modules/qunit/qunit/qunit.js in your HTML.

    If your project uses a custom npm frontend that locates packages elsewhere, you may need to generate the HTML dynamically and use require.resolve() to locate qunit/qunit/qunit.js and qunit/qunit/qunit.css. Alternatively, use one of the Integrations such as karma-qunit which do all of that for you.

  • Bower:

    Using Bower:

    bower install --save-dev qunit

    Then reference bower_components/qunit/qunit/qunit.css and bower_components/qunit/qunit/qunit.js in your HTML.

Further Reading