QUnit
This article relies largely or entirely on a single source. (February 2015) |
Initial release | 8 May 2008 |
---|---|
Stable release | 2.20.1[1]
/ 15 February 2024 |
Repository | |
Written in | MIT |
Website | qunitjs |
QUnit is a
client-side environments in web browsers, and server-side (e.g. Node.js
).
QUnit's assertion methods follow the CommonJS unit testing specification, which itself was influenced to some degree by QUnit.
History
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:[2]
assert.ok(boolean, string)
- Asserts that the provided value casts to boolean true.assert.equal(value1, value2, message)
- Compares two values, using thedouble-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:[3]
QUnit.test('a basic test example', function (assert) {
var obj = {};
assert.ok(true, 'Boolean true'); // passes
assert.ok(1, 'Number one'); // passes
assert.ok(false, 'Boolean false'); // fails
obj.start = 'Hello';
obj.end = 'Ciao';
assert.equal(obj.start, 'Hello', 'Opening greet'); // passes
assert.equal(obj.end, 'Goodbye', 'Closing greet'); // fails
});
See also
- List of unit testing frameworks
- Jasmine
- JavaScript framework
- JavaScript library
References
- ^ "Release 2.20.1". 15 February 2024. Retrieved 20 February 2024.
- ^ "Assert methods". QUnit API Documentation. Retrieved 2018-02-14.
- ^ "Cookbook: Example test". QUnit API Documentation. Retrieved 2014-06-02.