ember-pausable-test
This library provides a set of tools to pause async behavior in your tests to make it easier to assert intermediate state.
Usage
Installation
ember install ember-pausable-test
Acceptance Test
Suppose that we had a maybe-slow-loading route that rendered a loading template, with a model hook that looks like:
;
And, an acceptance test that looked something like this:
;
If we were to uncomment the assert
that checks for the loading spinner, it's possible that it has rendered by then; but not necessarily a guarantee. (This could lead to a flaky test!)
Instead, with this library, we can explicitly pause the model hook so we can test the loading state.
;;
And, in our test:
(note: You should always call reset()
in the afterEach
hook when using pauseOn
)
; ; ;
ember-concurrecncy
With Let's imagine a component that, when it renders, it pushes items onto a list every second.
There are two things I'd like to think about when testing this component:
- I want to test each step of the state as it changes
- I want the test to run fast (no need to wait a second between each step)
The component may look something like this:
;
<ul> {{#each objects as |object|}} <li>{{object.name}}</li> {{/each}}</ul>
By replacing the yield
statement with...
;
...we can setup our integration test like this:
;; ;
API
ember-pausable-test
-
pausable(yieldable: Any, tokenName: String)
In a test environment and when apauseOn
is registered with the giventokenName
, this method will return a promise that resolves whenpauseOn(tokenName).resume()
is called and resolves with theyieldable
.In non-test environments, or when there is no
pauseOn
registered, this will return theyieldable
directly.
ember-pausable-test/test-support
-
pauseOn(tokenName: String)
This regsiters a pause to happen when a correspondingpausable
is reached in the code.This method returns a
PauseToken
. -
PauseToken
-
resume()
This will resolve the promise that is pausing the promise chain. -
awaitPause()
This returns a promise that will resolve the next time the correspondingpausable()
block is hit. -
throwException()
This will cause the paused promise to reject, instead of resolve.
-
Configuration
Experimental support for unwrappping/removing pausable()
calls in non-test builds can be used by modifying your ember-cli-build.js
file:
const app = 'ember-pausable-test': strip: true ;
Collaborating
Running
ember serve
- Visit your app at http://localhost:4200.
Running Tests
yarn test
(Runsember try:each
to test your addon against multiple Ember versions)ember test
ember test --server
Building
ember build
For more information on using ember-cli, visit https://ember-cli.com/.
Releasing
ember release {--minor, --major, --patch}