Samiksha Jaiswal (Editor)

QUnit

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Written in
  
JavaScript

Website
  
qunitjs.com

License
  
MIT

Stable release
  
2.1.1 / 5 January 2017; 2 months ago (2017-01-05)

Type
  
Test automation framework

QUnit is a JavaScript unit testing framework. While heavily used by the jQuery Project for testing jQuery, jQuery UI and jQuery Mobile, it is a generic framework to test any JavaScript code. It supports server-side (e.g. node.js) and client-side environments.

Contents

QUnit's assertion methods follow the CommonJS unit testing specification, which itself was influenced to some degree by QUnit.

History

QUnit was originally developed by John Resig as part of jQuery. In 2008 it was extracted from the jQuery unit test source code to form its own project and became known as "QUnit". This allowed others to start using it for writing their unit tests. While the initial version of QUnit used jQuery for interaction with the DOM, a rewrite in 2009 made QUnit completely standalone.

Usage and examples

  • QUnit.module(string) - Defines a module, a grouping of one or more tests.
  • QUnit.test(string, function) - Defines a test.
  • QUnit uses a set of assertion method to provide semantic meaning in unit tests:

  • assert.ok(boolean, string) - Asserts that the provided value casts to boolean true.
  • assert.equal(value1, value2, message) - Compares two values, using the double-equal operator.
  • assert.deepEqual(value1, value2, message) - Compares two values based on their content, not just their identity.
  • assert.strictEqual(value1, value2, message) - Strictly compares two values, using the triple-equal operator.
  • A basic example would be as follows:

    References

    QUnit Wikipedia