Skip to content
Sinon sandbox test integration for QUnit
Branch: master
Clone or download
Latest commit 81a11e8 Jan 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
addon-test-support Add additional sinon functions to the test context. Jan 4, 2019
addon move test configuration to test-support Oct 10, 2015
app
blueprints/ember-sinon-qunit Replace jshint with eslint 🎉 Oct 18, 2016
config
tests
vendor
.editorconfig Upgrade via `ember init` Aug 13, 2016
.ember-cli
.eslintignore
.eslintrc.js Run Ember Init Jan 8, 2019
.gitignore Upgrade to Ember 3.3 & Sinon 6.0.1 Jul 24, 2018
.npmignore
.template-lintrc.js Upgrade to Ember 3.4 via ember init Sep 8, 2018
.travis.yml Upgrade to Ember 3.3 & Sinon 6.0.1 Jul 24, 2018
.watchmanconfig Initial Commit from Ember CLI v1.13.8 Oct 9, 2015
CONTRIBUTING.md
LICENSE.md
README.md
ember-cli-build.js
index.js Upgrade to Ember 3.4 via ember init Sep 8, 2018
package.json Released v3.4.0 Jan 8, 2019
testem.js Upgrade to Ember 3.3 & Sinon 6.0.1 Jul 24, 2018
yarn.lock Run Ember Init Jan 8, 2019

README.md

Ember Sinon QUnit

Build Status Ember Observer Score Code Climate Codacy Badge

This addon integrates Sinon & Ember-QUnit via Ember-Sinon, as inspired by Sinon-QUnit.

Why not simply use Ember-Sinon? Two reasons:

  1. Ember-Sinon does not handle cleanup of Ember-QUnit tests. Ember-Sinon-QUnit provides a test method that wraps Ember-QUnit while making each test callback a sandboxed Sinon environment. All spies/stubs created via the sandbox 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.

Installation

ember install ember-sinon-qunit

Usage

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) {
  setupTest(hooks);

  test('fooTransition action transitions to bar route', function (assert) {
    let route = this.owner.lookup('route:foo');
    const stub = this.stub(route, 'transitionTo');
    
    route.send('fooTransition');
    
    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';

License

This project is licensed under the MIT License.

You can’t perform that action at this time.