The powerful, easy-to-use testing framework for JavaScript applications
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Core functionality for defining and organizing tests into logical groups with support for various test types, execution modes, and module organization.
Define individual tests with descriptive names and test functions.
/**
* Define a standard test case
* @param {string} testName - Descriptive name for the test
* @param {Function} callback - Test function receiving assert object
*/
QUnit.test(testName, callback)Usage Examples:
import QUnit from "qunit";
QUnit.test("basic arithmetic", function(assert) {
assert.strictEqual(2 + 2, 4, "addition works");
assert.strictEqual(5 - 3, 2, "subtraction works");
});
QUnit.test("async operation", function(assert) {
const done = assert.async();
setTimeout(() => {
assert.ok(true, "async test completed");
done();
}, 100);
});Special test types for different execution scenarios.
/**
* Skip a test (will not run but appears in results)
* @param {string} testName - Test name
* @param {Function} [callback] - Test function (optional for skip)
*/
QUnit.skip(testName, callback)
/**
* TODO test (expected to fail, used for test-driven development)
* @param name - Test name
* @param callback - Test function
*/
function todo(name: string, callback: (assert: Assert) => void): void;
/**
* Only test (run this test exclusively, skip others)
* @param name - Test name
* @param callback - Test function
*/
function only(name: string, callback: (assert: Assert) => void): void;Usage Examples:
QUnit.skip("feature not implemented yet", function(assert) {
// This test will be skipped
assert.ok(false);
});
QUnit.todo("fix this failing test", function(assert) {
// This test is expected to fail
assert.strictEqual(buggyFunction(), "expected");
});
QUnit.only("debug this specific test", function(assert) {
// Only this test will run when .only() is used
assert.ok(true);
});Tests that run based on specific conditions.
/**
* Conditionally run test based on condition
* @param name - Test name
* @param condition - Boolean condition to evaluate
* @param callback - Test function
*/
function if(name: string, condition: boolean, callback: (assert: Assert) => void): void;Usage Examples:
QUnit.test.if("browser-specific test",
typeof window !== "undefined",
function(assert) {
assert.ok(window.navigator, "browser environment detected");
}
);Run the same test logic with different data sets.
/**
* Run test for each item in dataset
* @param name - Test name template
* @param dataset - Array of test data or object with named datasets
* @param callback - Test function receiving data and assert
*/
function each(
name: string,
dataset: any[] | Record<string, any>,
callback: (data: any, assert: Assert) => void
): void;Usage Examples:
QUnit.test.each("validate input", [
{ input: "hello", expected: true },
{ input: "", expected: false },
{ input: null, expected: false }
], function(data, assert) {
const result = validateInput(data.input);
assert.strictEqual(result, data.expected);
});
// Named datasets
QUnit.test.each("math operations", {
"addition": { a: 2, b: 3, expected: 5, op: "+" },
"subtraction": { a: 5, b: 2, expected: 3, op: "-" }
}, function(data, assert) {
const result = calculate(data.a, data.b, data.op);
assert.strictEqual(result, data.expected);
});Organize tests into logical groups with shared setup and teardown.
/**
* Define a test module
* @param name - Module name
* @param callback - Module definition function
*/
function module(name: string, callback?: () => void): void;
/**
* Define a test module with hooks
* @param name - Module name
* @param options - Module configuration with lifecycle hooks
* @param callback - Module definition function
*/
function module(
name: string,
options: ModuleOptions,
callback?: () => void
): void;
interface ModuleOptions {
/** Run once before all tests in module */
before?: () => void;
/** Run before each test in module */
beforeEach?: (assert: Assert) => void;
/** Run after each test in module */
afterEach?: (assert: Assert) => void;
/** Run once after all tests in module */
after?: () => void;
}Usage Examples:
QUnit.module("User Management", function() {
QUnit.test("user creation", function(assert) {
assert.ok(true);
});
QUnit.test("user deletion", function(assert) {
assert.ok(true);
});
});
// Module with hooks
QUnit.module("Database Tests", {
before: function() {
// Setup database connection
this.db = new Database();
},
beforeEach: function() {
// Clear test data before each test
this.db.clear();
},
afterEach: function() {
// Cleanup after each test
this.db.cleanup();
},
after: function() {
// Close database connection
this.db.close();
}
}, function() {
QUnit.test("data insertion", function(assert) {
// Test has access to this.db
assert.ok(this.db.insert({ name: "test" }));
});
});Special module types for different execution scenarios.
/**
* Skip entire module (no tests will run)
* @param name - Module name
* @param options - Module options (optional)
* @param callback - Module definition function (optional)
*/
function skip(
name: string,
options?: ModuleOptions,
callback?: () => void
): void;
/**
* TODO module (all tests expected to fail)
* @param name - Module name
* @param options - Module options (optional)
* @param callback - Module definition function
*/
function todo(
name: string,
options?: ModuleOptions,
callback: () => void
): void;
/**
* Only module (run only this module, skip others)
* @param name - Module name
* @param options - Module options (optional)
* @param callback - Module definition function
*/
function only(
name: string,
options?: ModuleOptions,
callback: () => void
): void;
/**
* Conditional module execution
* @param name - Module name
* @param condition - Boolean condition to evaluate
* @param options - Module options (optional)
* @param callback - Module definition function
*/
function if(
name: string,
condition: boolean,
options?: ModuleOptions,
callback?: () => void
): void;Global controls for test execution.
/**
* Manually start test suite (when autostart is false)
* @param count - Number of expected start calls (optional)
*/
function start(count?: number): void;
/**
* Get stack trace information
* @param offset - Number of stack frames to skip (optional)
* @returns Stack trace string
*/
function stack(offset?: number): string;Usage Examples:
// Disable autostart for manual control
QUnit.config.autostart = false;
// Load additional resources
loadTestData().then(() => {
// Start tests after resources are ready
QUnit.start();
});interface TestContext {
/** Test timeout value */
timeout?: number;
/** Custom test properties */
[key: string]: any;
}
interface ModuleContext {
/** Module name */
name: string;
/** Parent module (for nested modules) */
parent?: ModuleContext;
/** Custom module properties */
[key: string]: any;
}Install with Tessl CLI
npx tessl i tessl/npm-qunit