Ember Sinon QUnit is an Ember addon that seamlessly integrates the Sinon.js mocking and spying library with QUnit, specifically for Ember applications. Its primary function is to provide automatic cleanup of Sinon's state (spies, stubs, mocks) between individual QUnit tests, preventing leaks and ensuring test isolation. The current stable version is 7.5.0, with frequent updates driven by new Ember and Sinon releases, as seen in recent enhancements for Ember 5 and Sinon v18 support. A key differentiator is its hands-off management of Sinon sandboxes, removing the boilerplate of manual `sinon.restore()` calls, a common footgun when using Sinon directly with QUnit. It supports modern Ember versions (4.12+) and is compatible with Embroider and ember-auto-import v2, consolidating functionality previously spread across several related Ember Sinon addons.
npm install ember-sinon-qunitVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `ember-sinon-qunit` by calling `setupSinon()` in `test-helper.js` and then shows basic usage of `sinon` within QUnit tests, including automatic cleanup and a common pattern for stubbing `@action` decorators.
Ensure `sinon` is installed as a peer dependency (`yarn add -D sinon`) and meets the version requirement (v15+), and your Ember.js application is running at least version 4.0. Update your `test-helper.js` to use `import setupSinon from 'ember-sinon-qunit';` and remove any legacy `ember-sinon` configurations.
Always run `yarn add -D sinon` or `npm install --save-dev sinon` after installing `ember-sinon-qunit` to ensure the core Sinon library is available in your project.
Use the `.get()` modifier with `sinon.stub` or `sinon.spy` when targeting `@action` decorated methods. For example: `sinon.stub(service, 'methodToStub').get(() => null);` or `sinon.spy(service, 'methodToStub', ['get']);`
Upgrade to version 7.1.4 or higher to ensure correct TypeScript typings are available and properly referenced in `package.json`.
Trust the addon for automatic cleanup. Avoid manually creating or restoring Sinon sandboxes within tests that use `ember-sinon-qunit`, as it handles this for you. Simply import `sinon` and use it directly; the cleanup will be managed automatically.
Ensure `import sinon from 'sinon';` is at the top of your test file and that `sinon` is installed as a peer dependency: `yarn add -D sinon`.
Add `import setupSinon from 'ember-sinon-qunit';` and `setupSinon();` to your `tests/test-helper.js` file.
Install `sinon` as a development dependency: `npm install --save-dev sinon` or `yarn add -D sinon`.
When stubbing an `@action`, use `sinon.stub(service, 'actionName').get(() => /* stub implementation */);`