{"id":15645269,"url":"https://github.com/elwayman02/ember-sinon-qunit","last_synced_at":"2025-04-08T04:14:37.467Z","repository":{"id":1736499,"uuid":"43985995","full_name":"elwayman02/ember-sinon-qunit","owner":"elwayman02","description":"Sinon sandbox test integration for QUnit","archived":false,"fork":false,"pushed_at":"2025-03-31T13:30:10.000Z","size":7514,"stargazers_count":58,"open_issues_count":25,"forks_count":30,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-04T22:42:08.132Z","etag":null,"topics":["addon","ember","ember-qunit","ember-sinon","sinon","sinon-qunit"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elwayman02.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-10T00:18:37.000Z","updated_at":"2025-01-27T14:42:22.000Z","dependencies_parsed_at":"2023-02-19T08:00:44.542Z","dependency_job_id":"e4e34916-7683-4183-934d-bfcc22d8e850","html_url":"https://github.com/elwayman02/ember-sinon-qunit","commit_stats":{"total_commits":1091,"total_committers":30,"mean_commits":36.36666666666667,"dds":"0.31805682859761686","last_synced_commit":"0641f20ce9259ceae80fb001a6b871a8854ee52b"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elwayman02%2Fember-sinon-qunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elwayman02%2Fember-sinon-qunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elwayman02%2Fember-sinon-qunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elwayman02%2Fember-sinon-qunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elwayman02","download_url":"https://codeload.github.com/elwayman02/ember-sinon-qunit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261584,"owners_count":20910107,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addon","ember","ember-qunit","ember-sinon","sinon","sinon-qunit"],"created_at":"2024-10-03T12:05:35.819Z","updated_at":"2025-04-08T04:14:37.443Z","avatar_url":"https://github.com/elwayman02.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ember Sinon QUnit\n\n[![Build Status](https://github.com/elwayman02/ember-sinon-qunit/actions/workflows/ci.yml/badge.svg)](https://github.com/elwayman02/ember-sinon-qunit/actions/workflows/ci.yml)\n[![Ember Observer Score](http://emberobserver.com/badges/ember-sinon-qunit.svg)](http://emberobserver.com/addons/ember-sinon-qunit)\n[![Code Climate](https://codeclimate.com/github/elwayman02/ember-sinon-qunit/badges/gpa.svg)](https://codeclimate.com/github/elwayman02/ember-sinon-qunit)\n[![Codacy Badge](https://api.codacy.com/project/badge/8c6fbb028801423fbd4b1bfe17c9b1a0)](https://www.codacy.com/app/hawker-jordan/ember-sinon-qunit)\n\nThis addon integrates [`sinon`](http://jhawk.co/sinonjs) \u0026 [`ember-qunit`](http://jhawk.co/ember-qunit).\n\nWhy not simply use `sinon` alone?\n\n`sinon` does not handle cleanup of `ember-qunit` tests. While `sinon`\n[sandboxes itself](https://sinonjs.org/guides/migrating-to-5.0), it's up to the user to\nconsistently clean up `sinon` after each test. `ember-sinon-qunit` automatically\nrestores `sinon`'s state to ensure nothing is leaked between tests. All spies/stubs created\nwill be automatically restored to their original methods at the end of each test.\n\n## Compatibility\n\n- Sinon.js v15 or above\n- Ember.js v4.12 or above\n- Embroider or ember-auto-import v2\n\n## Installation\n\n```\nember install ember-sinon-qunit\n```\n\n`sinon` is a peerDependency of this addon, so install it with your favorite package manager as well, e.g. `yarn add -D sinon`.\n\n## Usage\n\nTo use, import the setup method into your `tests/test-helper.js` file and execute it.\n\n```js\nimport { setApplication } from '@ember/test-helpers';\nimport { start } from 'ember-qunit';\nimport Application from '../app';\nimport config from '../config/environment';\nimport setupSinon from 'ember-sinon-qunit';\n\nsetApplication(Application.create(config.APP));\n\nsetupSinon();\n\nstart();\n```\n\nThis will automatically wire-up `sinon`'s setup \u0026 restoration to QUnit's `testStart` and `testDone` respectively.\n\n#### Accessing `sinon` Within Tests\n\nIn each test you are able to access `sinon` via the `sinon` object available as an import in your tests:\n\n```js\nimport { module } from 'qunit';\nimport { test } from 'ember-qunit';\nimport sinon from 'sinon';\n\nmodule('Example test', function (hooks) {\n  hooks.beforeEach(function () {\n    this.testStub = sinon.stub();\n  });\n\n  test('sinon is wired up correctly', function (assert) {\n    this.testStub();\n\n    assert.ok(this.testStub.calledOnce, 'stub was called once');\n  });\n\n  test('sinon state restored after every test run', function (assert) {\n    assert.ok(this.testStub.notCalled, 'stub cleaned up after each test run');\n  });\n});\n```\n\nThe `sinon` object's state is automatically self-contained to each specific test, allowing you to\nsafely create mocks for your tests without worrying about any overrides leaking between each test.\n\n#### Using sinon with the `@action` decorator\n\nThe `@action` decorator is used with methods to bind them to the `this` of the class. The `@action`\ndoes this by wrapping the method in a property with the `getter` of the property returning the\noriginal method bound to `this`. That means when you wish to stub or spy the method, you have to treat it as a\nproperty not a method.\n\n```js\nlet stubAction = sinon.stub(service, 'methodToStub').get(function () {\n  return null;\n});\n\nlet spyAction = sinon.spy(service, 'methodToStub', ['get']);\n\nassert.ok(stubAction.get.calledOnce);\nassert.ok(spyAction.get.calledOnce);\n```\n\n## Migrating To `ember-sinon-qunit`\n\n| Read this [post](https://www.jordanhawker.com/p/187541610821) to learn more about the overhaul of this package. |\n| --------------------------------------------------------------------------------------------------------------- |\n\nThe above functionality replaces previous features within `ember-sinon-qunit`,\nas well as the sister addons [`ember-sinon-sinoff`](https://github.com/scalvert/ember-sinon-sinoff)\nand [`ember-sinon-sandbox`](https://github.com/scalvert/ember-sinon-sandbox).\nBelow, you will find simple instructions for migrating from each of these feature sets to the new patterns.\n\n### Migration from `sinon` 5+\n\n1. Import and consume `setupSinon`.\n1. Remove any manual calls to `sinon.restore()`. It won't hurt to leave them, but they are redundant now!\n\n### Migration from older versions of `sinon`\n\n1. Import and consume `setupSinon`.\n1. Remove calls to `sinon.createSandbox()`. Anywhere you used the `sandbox` object returned by this method,\n   you can now use `sinon` directly. See the [`sinon` Migration Guide](https://sinonjs.org/guides/migrating-to-5.0)\n   for more information.\n1. Remove any manual `restore()` calls for your sandboxes.\n\n### Migration from older versions of `ember-sinon-qunit`\n\n1. Revert to using the standard [`ember-qunit`](https://github.com/emberjs/ember-qunit) test import:\n   `import { test } from 'qunit';`\n1. Import and consume `setupSinon`.\n\n### Migration from `ember-sinon-sinoff` or `ember-sinon-sandbox`\n\n1. `import sinon from 'sinon';` within each test that currently uses a `sandbox`.\n1. Replace `this.sandbox` with the imported `sinon` object.\n1. Remove references to `setupSinonSinoff`/`setupSinonSandbox` from your tests.\n1. Import and consume `setupSinon`.\n\nOr, if you'd like to save some effort, try the following codemod [`ember-sinon-qunit-codemod`](https://github.com/sunwrobert/ember-sinon-qunit-codemod):\n\n```bash\ncd my-ember-app-or-addon\nnpx ember-sinon-qunit-codemod tests\n```\n\n## Contributing\n\nSee the [Contributing](CONTRIBUTING.md) guide for details.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felwayman02%2Fember-sinon-qunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felwayman02%2Fember-sinon-qunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felwayman02%2Fember-sinon-qunit/lists"}