Registry / testing / ember-sinon-qunit

ember-sinon-qunit

JSON →
library7.5.0jsnpmunverified

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-qunit
INSTALL
IMPORT
SIG · EMBER-SINON-QUNIT
E
ember-sinon-qunit
testingjavascriptv7.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

setupSinon
import setupSinon from 'ember-sinon-qunit';
const setupSinon = require('ember-sinon-qunit');
This is the primary function to call in your `test-helper.js` to enable automatic Sinon integration and cleanup. It's an ESM default export.
sinon
import sinon from 'sinon';
The Sinon object itself is imported directly from the `sinon` package into your test files for creating spies, stubs, and mocks. `ember-sinon-qunit` ensures its state is reset per test.

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.

import { setApplication } from '@ember/test-helpers'; import { start } from 'ember-qunit'; import Application from '../app'; import config from '../config/environment'; import setupSinon from 'ember-sinon-qunit'; import { module, test } from 'qunit'; import sinon from 'sinon'; setApplication(Application.create(config.APP)); setupSinon(); start(); module('Example test', function (hooks) { let myService; hooks.beforeEach(function() { // Assume myService is instantiated here or injected myService = { doSomething: () => 'original', @action someAction() { return 'action original'; } }; this.testStub = sinon.stub(myService, 'doSomething').returns('stubbed'); }); test('sinon is wired up correctly', function (assert) { assert.equal(myService.doSomething(), 'stubbed', 'stub returns stubbed value'); assert.ok(this.testStub.calledOnce, 'stub was called once'); }); test('sinon state restored after every test run', function (assert) { assert.notOk(this.testStub.called, 'stub cleaned up after each test run'); assert.equal(myService.doSomething(), 'original', 'method is restored'); // Example of stubbing an @action method let stubAction = sinon.stub(myService, 'someAction').get(() => null); myService.someAction(); assert.ok(stubAction.get.calledOnce, '@action stub getter was called'); }); });
Debug
Known issues
breakingVersion 7.0.0 introduced significant breaking changes. It dropped the `ember-sinon` dependency, moved to `ember-auto-import` for bundle integration, and strictly requires `sinon` version 15 or higher, as well as Ember.js v4.0 or higher (specifically documented v4.12+ for full compatibility).
fix
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.
affects: >=7.0.0
gotchaSinon is a peer dependency. Forgetting to install `sinon` explicitly will lead to runtime errors, even after installing `ember-sinon-qunit`.
fix
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.
affects: >=1.0.0
gotchaWhen stubbing or spying on methods decorated with Ember's `@action`, you must treat them as properties rather than direct methods. The `@action` decorator wraps the method in a property getter.
fix
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']);`
affects: >=7.0.0
breakingInitial TypeScript declaration files had issues with incorrect paths or missing exports, particularly for `setupSinon` and the root declaration file.
fix
Upgrade to version 7.1.4 or higher to ensure correct TypeScript typings are available and properly referenced in `package.json`.
affects: 7.1.0 - 7.1.3
gotchaThe addon provides automatic cleanup of `sinon`'s state between tests. While this is a feature, users accustomed to manual `sinon.sandbox.create()` and `sandbox.restore()` might inadvertently introduce their own manual cleanup, which is unnecessary and can potentially conflict.
fix
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.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'stub')
`sinon` is not correctly imported or installed.
fix
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`.
ReferenceError: setupSinon is not defined
`setupSinon` was not imported or called in your `tests/test-helper.js`.
fix
Add `import setupSinon from 'ember-sinon-qunit';` and `setupSinon();` to your `tests/test-helper.js` file.
Error: Cannot find module 'sinon'
The `sinon` package is missing from your `node_modules`.
fix
Install `sinon` as a development dependency: `npm install --save-dev sinon` or `yarn add -D sinon`.
TypeError: 'get' is not a function or its return value is not an object
Attempting to stub an `@action` decorated method without using the `.get()` syntax.
fix
When stubbing an `@action`, use `sinon.stub(service, 'actionName').get(() => /* stub implementation */);`
Upgrade
Version history
7.5.0latest on npm
Audit
Dependencies
ember-sourcerequiredPeer dependency, required for Ember application context. Requires >=3.28.0 (v7.0.0 breaking change to >=4.0).
qunitrequiredPeer dependency, the underlying testing framework. Requires ^2.0.0.
sinonrequiredPeer dependency, the core mocking library. Requires >=15.0.3 (v7.0.0 breaking change to v15+, updated to v18+ in 7.5.0).
Agent activity
2 hits · last 30 days
node
2
Resources
ember-sinon-qunit — npm install ember-sinon-qunit · libregistry