Registry / testing / ember-sinon

ember-sinon

JSON →
library5.0.0jsnpmunverified

Ember Sinon is an Ember CLI addon that seamlessly integrates the Sinon.js testing framework into Ember applications, simplifying the process of creating test spies, stubs, and mocks. The current stable version is 5.0.0, which supports Ember.js v3.16+ and Sinon.js v9.0.0+. Historically, the addon has maintained a consistent release cadence, often aligning its major versions with significant Ember and Sinon updates several times a year. Key differentiators include its tight integration with the Ember CLI test suite, making Sinon globally available in test environments without manual configuration, and its direct compatibility with `ember install` workflows. It offloads the complexity of managing Sinon.js versions and ensuring it's properly hooked into Ember's testing infrastructure, providing a ready-to-use solution for behavior verification in unit and integration tests.

npm install ember-sinon
INSTALL
IMPORT
SIG · EMBER-SINON
E
ember-sinon
testingjavascriptv5.0.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.

sinon
import sinon from 'sinon';
const sinon = require('sinon');
Sinon is made available as a global import within Ember CLI test environments. This addon primarily targets modern Ember CLI projects which utilize ES Modules. Direct CommonJS `require` is not the idiomatic approach.

Demonstrates how to import and use Sinon spies and stubs within an Ember QUnit test to verify function calls and mock asynchronous operations.

import sinon from 'sinon'; import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; // Assuming standard Ember QUnit setup module('Unit | Service | my-example-service', function(hooks) { setupTest(hooks); test('doSomething() should run the callback passed with expected arguments', function(assert) { assert.expect(2); // QUnit assertion count let myService = this.owner.lookup('service:my-example-service'); // Assuming a service named 'my-example-service' // Create a spy to observe function calls let spy = sinon.spy(); myService.doSomething(spy, 'test_argument'); // Assert using Sinon's built-in assertion methods sinon.assert.calledOnce(spy); sinon.assert.calledWith(spy, 'test_argument'); }); test('fetchData() should return stubbed data without making an actual network request', async function(assert) { assert.expect(1); let myService = this.owner.lookup('service:my-example-service'); // Create a stub for a method that might make an external call (e.g., fetch, AJAX) let stub = sinon.stub(myService, 'performNetworkRequest').returns(Promise.resolve({ id: 123, status: 'success' })); let result = await myService.fetchData(); assert.deepEqual(result, { id: 123, status: 'success' }, 'should return the predefined stubbed data'); // Restore the original method after the test to avoid side effects stub.restore(); }); });
Debug
Known issues
breakingVersion 5.0.0 introduces stricter compatibility requirements, specifically needing Ember.js v3.16 or above and Sinon.js v9.0.0 or above. Projects on older Ember or Sinon versions must upgrade their dependencies before updating.
fix
Ensure your project's `ember-source` is at least `^3.16.0` and `sinon` is `^9.0.0` in `package.json`, then run `npm install`.
affects: >=5.0.0
breakingVersion 4.0.0 of `ember-sinon` dropped support for Node.js 6. Subsequent versions, including 5.0.0, require Node.js v10 or above. Running with older Node versions will lead to installation and runtime errors.
fix
Upgrade your Node.js runtime environment to version 10 or higher. Tools like `nvm` (Node Version Manager) can help manage multiple Node.js versions efficiently.
affects: >=4.0.0
gotchaWhile `ember-sinon` makes Sinon available, for specific integration with Ember-QUnit test helpers (like `this.spy()`, `this.stub()`), you should also install `ember-sinon-qunit`. `ember-sinon` provides the Sinon library; `ember-sinon-qunit` provides the QUnit test context helpers.
fix
If you require `this.spy` or `this.stub` test helpers within your QUnit modules, run `ember install ember-sinon-qunit` alongside `ember-sinon`.
affects: all
Errors
Common errors & fixes
ReferenceError: sinon is not defined
Attempting to use `sinon` without importing it or outside of a test environment where `ember-sinon` makes it available.
fix
Ensure `import sinon from 'sinon';` is present at the top of your test file and that you are executing the code within an Ember CLI test suite.
Error: The 'ember-sinon' addon requires Ember.js vX.Y.Z or above.
The Ember.js version in your project is older than the minimum required by the installed `ember-sinon` version.
fix
Check the `Compatibility` section of the `ember-sinon` README for your specific version, then upgrade your `ember-source` dependency in `package.json` to meet the minimum requirement.
Module not found: Error: Can't resolve 'sinon' in 'path/to/your/test/file.js'
This error typically indicates that `ember-sinon` was not successfully installed or that the build system cannot locate the Sinon module provided by the addon.
fix
Verify that `ember install ember-sinon` completed without errors. Ensure your `package.json` includes `ember-sinon` and try deleting `node_modules` and `tmp` directories, then run `npm install && ember test`.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
sinonrequiredProvides the core mocking, stubbing, and spying functionality integrated by this Ember addon for testing purposes.
Agent activity
2 hits · last 30 days
node
2
Resources
ember-sinon — npm install ember-sinon · libregistry