QUnit is a widely adopted, powerful, and easy-to-use JavaScript testing framework, providing a clear and efficient API for writing unit and integration tests. Originally developed to test the jQuery library, it has significantly matured into a versatile, standalone solution compatible with modern JavaScript applications across various environments, including Node.js (version 10+) and web browsers. The framework is currently stable at version 2.25.0, with an active release cadence that frequently introduces new features and improvements, often focusing on developer experience and compliance with modern JavaScript ecosystems. A significant upcoming release, 3.0.0-rc1, is already available, introducing native ES module (ESM) distribution, which is automatically utilized by Node.js when using `import` statements, marking a key modernization step for module resolution. QUnit's core philosophy centers on simplicity and clarity, which is evident in its direct assertion style, intuitive modular test organization with `QUnit.module()`, programmatic test filtering capabilities via `QUnit.config.testFilter`, and robust support for both synchronous and complex asynchronous testing patterns. It consistently focuses on clear test reporting and comprehensive TAP compliance, ensuring seamless integration with various Continuous Integration/Continuous Deployment (CI/CD) pipelines and test runners.
npm install qunitVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining a QUnit module, utilizing `beforeEach` and `afterEach` hooks, writing both synchronous and asynchronous test cases, and employing various QUnit assertion methods. This example is set up to run using native ES modules in a Node.js environment.
For Node.js projects, update imports to `import QUnit from 'qunit';` and ensure `"type": "module"` is present in your `package.json` file. Alternatively, use `.cjs` file extensions for files that must remain CommonJS.
Review existing `before` and `after` hook implementations, especially in nested module structures, to ensure their behavior aligns with the new context inheritance model. Adjust any logic that might have relied on the previous behavior or unintentional state sharing.
For tests that use both `assert.expect()` and `assert.verifySteps()`, you will need to adjust the value passed to `assert.expect()` to exclude the number of `assert.step()` calls. Monitor QUnit v3 documentation for the final specification on this change.
For callback-based asynchronous operations, obtain a `done` callback using `const done = assert.async();` at the start of the test and invoke `done();` once all asynchronous operations have completed. For Promise-based asynchronous operations, simply return the Promise from the test function.
Ensure `qunit` is installed (`npm install qunit`). In Node.js, verify that `import QUnit from 'qunit';` (for ESM, v3+) or `require('qunit');` (for CJS) is at the top of your test runner or test files. In a browser, confirm that the `<script src="qunit.js"></script>` tag is correctly placed before your test scripts in the HTML.It is often best to remove `assert.expect()` entirely as it can be brittle and is often unnecessary with modern test practices. If retained, meticulously adjust the `N` value passed to `assert.expect()` to precisely reflect the actual number of `assert` method calls that will execute in the test, keeping in mind the change in behavior for `assert.step()` in v3.
This problem shares the same root cause as 'ReferenceError: QUnit is not defined'. Double-check your QUnit import statements (ESM `import` for v3+ Node.js, or CJS `require` for older Node/CJS contexts) or verify script tag inclusion for browser-based testing.
No dependency data recorded yet.