This package has been deprecated

Author message:

This package is deprecated. Please use ember-sinon-sinoff

ember-sinon-sandbox

2.0.2 • Public • Published

ember-sinon-sandbox

Build Status npm version

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.

Installation

Run:

ember install ember-sinon-sandbox

Usage

The ember-sinon-sandbox addon supports two different API versions:

  1. The classic API, which automatically wires up sandbox creation and restoration to QUnit.testStart and QUnit.testDone respectively
  2. The new QUnit hooks API, which takes a hooks object and wires up sandbox creation and restoration to beforeEach and afterEach of the module.

Classic API

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

import setupSinonSandbox from 'ember-sinon-sandbox/test-support/setup-global-sinon-sandbox';
 
...
 
setupSinonSandbox();

This will automatically wire-up the sandbox sinon.sandbox.create and sandbox.restore methods to QUnit testStart and testDone respectively.

QUnit hooks API

To use, import the setup method from within your test file and execute it.

import { setupSinonSandbox } from 'ember-sinon-sandbox/test-support';
 
...
 
module('my module', function(hooks) {
  setupSinonSandbox(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.

Accessing Sinon from Within Tests

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.

Incremental Migration

To ease the path to migrate to using ember-sinon-sandbox'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();
  ...
});

Contributing

Installation

  • git clone git@github.com:scalvert/ember-sinon-sandbox.git
  • cd ember-sinon-sandbox
  • yarn

Running Tests

  • yarn test
  • ember test
  • ember test --server

Readme

Keywords

Package Sidebar

Install

npm i ember-sinon-sandbox

Weekly Downloads

1

Version

2.0.2

License

MIT

Unpacked Size

8.5 kB

Total Files

10

Last publish

Collaborators

  • scalvert