{"id":17001,"library":"ember-sinon","title":"Ember Sinon","description":"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.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/csantero/ember-sinon","tags":["javascript","ember-addon","sinon"],"install":[{"cmd":"npm install ember-sinon","lang":"bash","label":"npm"},{"cmd":"yarn add ember-sinon","lang":"bash","label":"yarn"},{"cmd":"pnpm add ember-sinon","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the core mocking, stubbing, and spying functionality integrated by this Ember addon for testing purposes.","package":"sinon"}],"imports":[{"note":"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.","wrong":"const sinon = require('sinon');","symbol":"sinon","correct":"import sinon from 'sinon';"}],"quickstart":{"code":"import sinon from 'sinon';\nimport { module, test } from 'qunit';\nimport { setupTest } from 'ember-qunit'; // Assuming standard Ember QUnit setup\n\nmodule('Unit | Service | my-example-service', function(hooks) {\n  setupTest(hooks);\n\n  test('doSomething() should run the callback passed with expected arguments', function(assert) {\n    assert.expect(2); // QUnit assertion count\n    let myService = this.owner.lookup('service:my-example-service'); // Assuming a service named 'my-example-service'\n\n    // Create a spy to observe function calls\n    let spy = sinon.spy();\n    myService.doSomething(spy, 'test_argument');\n\n    // Assert using Sinon's built-in assertion methods\n    sinon.assert.calledOnce(spy);\n    sinon.assert.calledWith(spy, 'test_argument');\n  });\n\n  test('fetchData() should return stubbed data without making an actual network request', async function(assert) {\n    assert.expect(1);\n    let myService = this.owner.lookup('service:my-example-service');\n\n    // Create a stub for a method that might make an external call (e.g., fetch, AJAX)\n    let stub = sinon.stub(myService, 'performNetworkRequest').returns(Promise.resolve({ id: 123, status: 'success' }));\n\n    let result = await myService.fetchData();\n\n    assert.deepEqual(result, { id: 123, status: 'success' }, 'should return the predefined stubbed data');\n\n    // Restore the original method after the test to avoid side effects\n    stub.restore();\n  });\n});","lang":"javascript","description":"Demonstrates how to import and use Sinon spies and stubs within an Ember QUnit test to verify function calls and mock asynchronous operations."},"warnings":[{"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`.","message":"Version 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.","severity":"breaking","affected_versions":">=5.0.0"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"If you require `this.spy` or `this.stub` test helpers within your QUnit modules, run `ember install ember-sinon-qunit` alongside `ember-sinon`.","message":"While `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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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.","cause":"Attempting to use `sinon` without importing it or outside of a test environment where `ember-sinon` makes it available.","error":"ReferenceError: sinon is not defined"},{"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.","cause":"The Ember.js version in your project is older than the minimum required by the installed `ember-sinon` version.","error":"Error: The 'ember-sinon' addon requires Ember.js vX.Y.Z or above."},{"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`.","cause":"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.","error":"Module not found: Error: Can't resolve 'sinon' in 'path/to/your/test/file.js'"}],"ecosystem":"npm","meta_description":null}