https://github.com/nullvoxpopuli/ember-test-helpers-extra
Additional test helpers that build upon the primitives in @ember/test-helpers
https://github.com/nullvoxpopuli/ember-test-helpers-extra
Last synced: 6 months ago
JSON representation
Additional test helpers that build upon the primitives in @ember/test-helpers
- Host: GitHub
- URL: https://github.com/nullvoxpopuli/ember-test-helpers-extra
- Owner: NullVoxPopuli
- Created: 2019-07-27T21:31:02.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-28T15:28:23.000Z (almost 7 years ago)
- Last Synced: 2025-04-06T20:48:15.771Z (over 1 year ago)
- Language: TypeScript
- Size: 18.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ember-test-helpers-extra
## Install
```
yarn add --dev ember-test-helpers-extra
```
## Usage
### `getService`
Retreives a service by name.
```ts
let store = getService('store');
```
### `stubService`
Stubs a service by name, using either an object or Service class definition
```ts
stubService('my-service', {
foo() {
return false;
}
});
```
```ts
stubService('my-service', Service.extend({
foo() {
return false;
}
}));
```
### `setupServiceStub`
This helper is for a special situation in which you need to
stub a service that has already been registered and accessed,
which prevents you from re-registering a service stub.
This stems from (instance) initializers accessing the services.
Generally, it's best practice to avoid initializers -- but sometimes
legacy code has utilized their ability to reduce repetition,
or run some boot-time code.
Related issue reported in ember-cli-qunit: https://github.com/ember-cli/ember-cli-qunit/issues/203#issuecomment-366261794
```ts
module('Integration | Component | my-component', function(hooks) {
setupRenderingTest(hooks);
setupServiceStub(hooks, 'my-service', {
foo() {
false;
}
})
});
```