# QUnit — Powerful JavaScript Unit Testing Framework > QUnit is a mature, easy-to-use JavaScript unit testing framework used by jQuery, Ember.js, and many other projects for reliable browser and Node.js testing. ## Install Save in your project root: # QUnit — Powerful JavaScript Unit Testing Framework ## Quick Use ```bash npm install --save-dev qunit # Create test/example.js: # const { test } = QUnit; # test("basic arithmetic", assert => { # assert.equal(2 + 2, 4, "two plus two equals four"); # }); npx qunit test/ ``` ## Introduction QUnit is one of the oldest and most battle-tested JavaScript testing frameworks, originally developed for testing jQuery. It runs in both browsers and Node.js, providing a simple API for writing and organizing unit tests with zero configuration needed. ## What QUnit Does - Runs unit tests in browsers and Node.js with a consistent API - Provides a built-in assertion library with equal, deepEqual, and throws methods - Supports async testing with native Promise and callback patterns - Offers a visual HTML test runner for browser-based debugging - Groups tests into modules with shared setup and teardown hooks ## Architecture Overview QUnit operates as a single-file testing library that registers test functions, runs them sequentially within modules, and reports results through configurable reporters. In browser mode it renders an interactive HTML page with pass/fail indicators and filtering. In Node.js it uses a CLI runner that outputs TAP format or console-friendly results. ## Self-Hosting & Configuration - Install via npm for Node.js or include the script tag for browser testing - Place test files in a test directory and run with npx qunit - Configure browser testing by creating an HTML file that loads QUnit and test scripts - Set global options like reorder and seed for test execution behavior - Integrate with CI using TAP output format or JUnit reporters ## Key Features - Zero-config Node.js test runner with automatic test file discovery - Interactive browser test runner with URL-based test filtering - Built-in support for async tests using Promises and callbacks - Module-based test organization with nested scoping - Lightweight footprint with no external dependencies ## Comparison with Similar Tools - **Jest** — full-featured framework with mocking and snapshots; QUnit is simpler with a smaller API surface - **Mocha** — flexible runner requiring separate assertion library; QUnit includes assertions built-in - **Jasmine** — BDD-style framework; QUnit uses a straightforward procedural test style - **Vitest** — Vite-native modern testing; QUnit predates modern bundlers and works without build tools - **AVA** — concurrent Node.js runner; QUnit runs tests sequentially for deterministic results ## FAQ **Q: Is QUnit only for testing jQuery code?** A: No, QUnit is a general-purpose JavaScript testing framework used by many projects beyond jQuery, including Ember.js. **Q: Can I run QUnit tests in CI?** A: Yes, the CLI runner outputs TAP format by default, which most CI systems can parse. **Q: Does QUnit support ES modules?** A: Yes, QUnit works with ES modules in both Node.js and browser environments. **Q: How do I test async code?** A: Return a Promise from your test function or use assert.async() for callback-based async code. ## Sources - https://github.com/qunitjs/qunit - https://qunitjs.com --- Source: https://tokrepo.com/en/workflows/asset-1b3bb559 Author: AI Open Source