Skip to content
Sinon sandbox test integration for QUnit
JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
addon-test-support [bugfix] Fix Ember.deprecate syntax Sep 12, 2019
addon move test configuration to test-support Oct 10, 2015
app Initial Commit from Ember CLI v1.13.8 Oct 9, 2015
config Upgrade to Ember 3.12 Sep 5, 2019
tests [bugfix] Fix Ember.deprecate syntax Sep 12, 2019
.editorconfig Upgrade via `ember init` Aug 13, 2016
.ember-cli Initial Commit from Ember CLI v1.13.8 Oct 9, 2015
.eslintignore Run Ember Init Jan 8, 2019
.gitignore Upgrade to Ember 3.10 May 22, 2019
.npmignore Upgrade to Ember 3.10 May 22, 2019
.template-lintrc.js Upgrade to Ember 3.4 via ember init Sep 8, 2018
.travis.yml Upgrade to Ember 3.12 Sep 5, 2019
.watchmanconfig Initial Commit from Ember CLI v1.13.8 Oct 9, 2015 Run Ember Init Jan 8, 2019 Upgrade addon via `ember init` Feb 22, 2016 Add blog post to README Sep 6, 2019
ember-cli-build.js Upgrade to Ember 3 Mar 14, 2018
index.js Pass correct tree Sep 5, 2019
package.json Released v4.0.1 Sep 18, 2019
testem.js Upgrade to Ember 3.12 Sep 5, 2019

Ember Sinon QUnit

Build Status Ember Observer Score Code Climate Codacy Badge

This addon integrates sinon & ember-qunit via ember-sinon, originally inspired by sinon-qunit.

Why not simply use ember-sinon alone? Two reasons:

  1. ember-sinon does not handle cleanup of ember-qunit tests. While sinon sandboxes itself, it's up to the user to consistently clean up sinon after each test. ember-sinon-qunit automatically restores sinon's state to ensure nothing is leaked between tests. All spies/stubs created will be automatically restored to their original methods at the end of each test.
  2. sinon is a framework-agnostic library; as such, ember-sinon should be as well. This addon exists to enable ember-sinon to remove its qunit specific functionality, making it easier to utilize ember-sinon with other addons like ember-cli-mocha, for example.


  • Sinon.js v5.0.0 or above
  • Ember.js v3.4 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above


ember install ember-sinon-qunit


To use, import the setup method into your tests/test-helper.js file and execute it.

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';

This will automatically wire-up sinon's setup & restoration to QUnit's testStart and testDone respectively.

Accessing sinon Within Tests

In each test you are able to access sinon via the sinon object available as an import in your tests:

import sinon from 'sinon';


test('very important test happening here', function(assert) {
  const spy = sinon.spy();


The sinon object's state is automatically self-contained to each specific test, allowing you to safely create mocks for your tests without worrying about any overrides leaking between each test.

Migrating To ember-sinon-qunit

Read this post to learn more about the overhaul of this package.

The above functionality replaces previous features within ember-sinon-qunit, as well as the sister addons ember-sinon-sinoff and ember-sinon-sandbox. Below, you will find simple instructions for migrating from each of these feature sets to the new patterns.

Migration from sinon 5+

  1. Import and consume setupSinon.
  2. Remove any manual calls to sinon.restore(). It won't hurt to leave them, but they are redundant now!

Migration from older versions of sinon

  1. Import and consume setupSinon.
  2. Remove calls to sinon.createSandbox(). Anywhere you used the sandbox object returned by this method, you can now use sinon directly. See the sinon Migration Guide for more information.
  3. Remove any manual restore() calls for your sandboxes.

Migration from older versions of ember-sinon-qunit

  1. Revert to using the standard ember-qunit test import: import { test } from 'qunit';
  2. Import and consume setupSinon.

Migration from ember-sinon-sinoff or ember-sinon-sandbox

  1. import sinon from 'sinon'; within each test that currently uses a sandbox.
  2. Replace this.sandbox with the imported sinon object.
  3. Remove references to setupSinonSinoff/setupSinonSandbox from your tests.
  4. Import and consume setupSinon.

Deprecated Features

Note: The following features are deprecated and should not be used, as they will be removed in a future major release.

Import ember-sinon-qunit's test method into your tests in place of ember-qunit's test. This creates a sinon sandbox around that test via sinon's test API. Then, you can access the following sinon functions via this within the test callback:

  • spy,
  • stub,
  • mock,
  • fake,
  • replace
  • replaceGetter
  • replaceSetter
  • sandbox
import { module } from 'qunit';
import test from 'ember-sinon-qunit/test-support/test';
import { setupTest } from 'ember-qunit';

module('Unit | Route | foo', function(hooks) {

  test('fooTransition action transitions to bar route', function (assert) {
    let route = this.owner.lookup('route:foo');
    const stub = this.stub(route, 'transitionTo');
    assert.ok(stub.calledOnce, 'transitionTo was called once');
    assert.ok(stub.calledWithExactly('bar'), 'bar was passed to transitionTo');

That's it! You can use this test method in place of all ember-qunit tests if you want, without any loss of functionality. Or, you can import them both into the same test to be used only when you need sinon:

import { module } from 'qunit';
import test from 'ember-sinon-qunit/test-support/test';
import { setupTest } from 'ember-qunit';


See the Contributing guide for details.


This project is licensed under the MIT License.

You can’t perform that action at this time.