QUnit: A JavaScript Unit Testing framework.
What is QUnit?
QUnit is a powerful, easy-to-use JavaScript unit testing framework. It's used by the jQuery, jQuery UI and jQuery Mobile projects and is capable of testing any generic JavaScript code, including itself!
Getting Started
In The Browser
A minimal QUnit test setup:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
|
The contents of tests.js:
1
2
3
|
|
The result:
In Node
Install QUnit globally so you can use the CLI:
1
|
|
Create test files in a test
directory and then simply run:
1
|
|
And you should see some output like:
1
2
3
4
5
6
7
8
|
|
And that is it! While QUnit defaults to looking for test files in test
, you can also put them anywhere and then specify file paths or glob expressions:
1
|
|
To view the additional supported options, simply run:
1
|
|
Download
QUnit is available from the jQuery CDN hosted by MaxCDN.
Current Release - v2.9.1
- qunit-2.9.1.js
- qunit-2.9.1.css
- Changelog
- NPM:
- YARN:
- Bower:
To test the latest features and bug fixes to QUnit, a version automatically generated from the latest commit to the QUnit Git repository is also available for use.
Package Name Prior to 2.4.1
Prior to version 2.4.1, QUnit was published under the name qunitjs
on NPM. If you wish to install an older version of QUnit on Node, you will want to use the qunitjs
package. The qunit
package prior to 2.4.1 is an alternative CLI that is now published as node-qunit
.
Browser Support
QUnit currently supports the same browsers as jQuery 3.x.
For legacy browser support, including Internet Explorer versions lower than IE9, please use the 1.x series of QUnit.
Node Support
QUnit follows the Node Long-term Support (LTS) Schedule. Support is provided for Current, Active, and Maintenance releases.
Learn More
- Check out the API documentation or the Cookbook to learn how to use QUnit
- To see more examples, check out the unit tests of jQuery, jQuery UI or the jQuery Validation Plugin.
- For custom assertions, reporters and themes, check out official and third-party plugins
- Please post to the QUnit and testing forum for anything related to QUnit or testing in general.
- For announcements, follow @qunitjs
Get Involved
- The code is located at: https://github.com/qunitjs/qunit
- The code for this site is also on GitHub, with the API documentation in a separate folder in the main repository.
- Find the QUnit team on Gitter and in #jquery-dev on Freenode.
History
QUnit was originally developed by John Resig as part of jQuery. In 2008 it got its own home, name and API documentation, allowing others to use it for their unit testing as well. At the time it still depended on jQuery. A rewrite in 2009 fixed that, and now QUnit runs completely standalone.
QUnit's assertion methods follow the CommonJS Unit Testing specification, which was to some degree influenced by QUnit.