An Ember addon that automatically restores sinon after each test.
This package has been deprecated: Please use ember-sinon-qunit. |
---|
This addon adds automatic sandboxing of sinon to your QUnit tests. This ensures that sinon is correctly isolated and doesn’t leak state between test executions.
Run:
ember install ember-sinon-sinoff
The ember-sinon-sinoff
addon supports two different API versions:
QUnit.testStart
and QUnit.testDone
respectivelyhooks
object and wires up sandbox creation and restoration to beforeEach
and afterEach
of the module.To use, import the setup method from within your tests/test-helper.js
file and execute it.
import setupSinonSinoff from 'ember-sinon-sinoff/test-support/setup-global-sinon-sinoff';
...
setupSinonSinoff();
This will automatically wire-up the sandbox sinon.sandbox.create
and sandbox.restore
methods to QUnit testStart
and testDone
respectively.
hooks
APITo use, import the setup method from within your test file and execute it.
import { setupSinonSinoff } from 'ember-sinon-sinoff/test-support';
...
module('my module', function(hooks) {
setupSinonSinoff(hooks);
test('my test', function(assert) {
...
})
})
This will automatically wire-up the sandbox sinon.createSandbox
and sandbox.restore
methods to the module’s beforeEach
and afterEach
respectively.
In each test you will be able to access the same sandboxed version of sinon via the this.sandbox
property available within the test’s scope:
test('very important test happening here', function(assert) {
const spy = this.sandbox.spy();
...
});
Both the global sinon object and the this.sandbox
convenience property point to the same, test-specific instance of a sinon sandbox.
To ease the path to migrate to using ember-sinon-sinoff
‘s version of a fully sandboxed sinon, the sandbox that’s provided includes a create
method, which returns the same instance of the sandbox referenced by this.sandbox
. This allows you to incrementally remove usages of sandboxing within your application.
test('another equally important test', function(assert) {
// sandbox === this.sandbox
const sandbox = sinon.sandbox.create();
...
});
git clone git@github.com:scalvert/ember-sinon-sinoff.git
cd ember-sinon-sinoff
yarn
yarn test
ember test
ember test --server