What is QUnit?
QUnit is a powerful, easy-to-use JavaScript unit test suite. It's used by the
jQuery, jQuery UI and jQuery Mobile projects and is capable of testing any generic JavaScript
code, including itself!
Get Involved
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 dependended on jQuery. A rewrite in 2009 fixed that, now QUnit runs completelty standalone.
QUnit's assertion methods follow the CommonJS Unit Testing specification, which was to some degree influenced by QUnit. A notable exception is throws (a reserved JavaScript identifier), which is called raises in QUnit.
Getting Started
A minimal QUnit test setup:
<html>
<head>
<meta charset="utf-8" />
<title>QUnit Example</title>
<link rel="stylesheet" href="/resources/css/qunit.css" />
</head>
<body>
<div id="qunit"></div>
<script src="/resources/js/qunit.js"></script>
<script src="/tests.js"></script>
</body>
</html>
The contents of tests.js:
test( "hello test", function() {
ok( 1 == "1", "Passed!" );
});
The result: