{"id":22354052,"url":"https://github.com/movableink/ember-pausable-test","last_synced_at":"2025-09-03T18:36:00.490Z","repository":{"id":142003936,"uuid":"107562809","full_name":"movableink/ember-pausable-test","owner":"movableink","description":"Wrangle your very async tests. ","archived":false,"fork":false,"pushed_at":"2018-03-06T13:34:27.000Z","size":192,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-01-31T13:43:41.945Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/movableink.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2017-10-19T15:12:40.000Z","updated_at":"2017-11-12T19:46:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"c303418e-7952-4d62-b303-1dc67453f9e0","html_url":"https://github.com/movableink/ember-pausable-test","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/movableink%2Fember-pausable-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/movableink%2Fember-pausable-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/movableink%2Fember-pausable-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/movableink%2Fember-pausable-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/movableink","download_url":"https://codeload.github.com/movableink/ember-pausable-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245653019,"owners_count":20650617,"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":[],"created_at":"2024-12-04T13:11:01.080Z","updated_at":"2025-03-26T12:28:34.240Z","avatar_url":"https://github.com/movableink.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ember-pausable-test\n\nThis library provides a set of tools to pause async behavior in your tests to make it easier to assert intermediate state.\n\n## Usage\n--------\n\n### Installation\n\n* `ember install ember-pausable-test`\n\n### Acceptance Test\n\nSuppose that we had a maybe-slow-loading route that rendered a loading template, with a model hook that looks like:\n\n```js\nimport Route from '@ember/routing/route';\n\nexport default Route.extend({\n  model({ id }) {\n    return this.store.find('friends', id);\n  }\n})\n```\n\nAnd, an acceptance test that looked something like this:\n\n```js\nit('shows a friend', async function(assert) {\n  visit('/friends/1');\n\n  // Where do we assert this!?!\n  // assert.ok(find('.loading-spinner').length, 'loading screen visible!');\n\n  await andThen(() =\u003e {});\n\n  assert.ok(find('.friend-name').text().trim(), 'Steve');\n});\n```\n\nIf 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!)\n\nInstead, with this library, we can explicitly pause the model hook so we can test the loading state.\n\n```js\nimport Route from '@ember/routing/route';\nimport { pausable } from 'ember-pausable-test';\n\nexport default Route.extend({\n  model({ id }) {\n    const friend = this.store.find('friends', id);\n    return pausable(friend, 'friend-promise');\n  }\n})\n```\n\nAnd, in our test:\n\n(_note:_ You should always call `reset()` in the `afterEach` hook when using `pauseOn`)\n\n```js\nimport { pauseOn, reset } from 'ember-pausable-test/test-support';\n\nmoduleForAcceptance('Acceptance | friend', {\n  afterEach() {\n    reset();\n  }\n});\n\nit('shows a friend', async function(assert) {\n  const { resume, awaitPause } = pauseOn('friend-promise');\n\n  visit('/friends/1');\n\n  await awaitPause();\n\n  assert.ok(find('.loading-spinner').length, 'loading screen visible!');\n\n  resume();\n\n  await andThen(() =\u003e {});\n\n  assert.ok(find('.friend-name').text().trim(), 'Steve');\n});\n```\n\n### With `ember-concurrecncy`\n\nLet's imagine a component that, when it renders, it pushes items onto a list every second.\n\nThere are two things I'd like to think about when testing this component:\n\n- I want to test each step of the state as it changes\n- I want the test to run fast (no need to wait a second between each step)\n\nThe component may look something like this:\n\n```js\nexport default Component.extend({\n  didInsertElement() {\n    set(this, 'objects', A([]));\n    get(this, 'myTask').perform();\n  },\n\n  myTask: task(function *() {\n    const objects = get(this, 'objects');\n    const waitTime = testing ? 0 : 1000;\n    let idx = -1;\n\n    while (++idx \u003c 5) {\n      objects.pushObject({ name: `Step ${idx}` });\n      yield timeout(waitTime);\n    }\n  })\n});\n```\n\n```hbs\n\u003cul\u003e\n  {{#each objects as |object|}}\n    \u003cli\u003e{{object.name}}\u003c/li\u003e\n  {{/each}}\n\u003c/ul\u003e\n```\n\nBy replacing the `yield` statement with...\n\n```js\nyield pausable(timeout(waitTime), 'state-progressor');\n```\n\n...we can setup our integration test like this:\n\n```js\nimport { pauseOn } from 'ember-pausable-test/test-support';\nimport wait from 'ember-test-helpers/wait';\n\ntest('it renders each of the steps', async function(assert) {\n  const { resume, awaitPause } = pauseOn('state-progressor');\n\n  this.render(hbs`{{state-progressor}}`);\n\n  await awaitPause();\n  assert.equal(this.$('ul \u003e li').length, 1);\n  resume();\n\n  await awaitPause();\n  assert.equal(this.$('ul \u003e li').length, 2);\n  resume();\n\n  await awaitPause();\n  assert.equal(this.$('ul \u003e li').length, 3);\n  resume();\n\n  await awaitPause();\n  assert.equal(this.$('ul \u003e li').length, 4);\n  resume();\n\n  await wait();\n  assert.equal(this.$('ul \u003e li').length, 5);\n});\n```\n\n### API\n\n#### `ember-pausable-test`\n\n- `pausable(yieldable: Any, tokenName: String)`\n  In a test environment and when a `pauseOn` is registered with the given `tokenName`, this method will return a promise that resolves\n  when `pauseOn(tokenName).resume()` is called and resolves with the `yieldable`.\n\n  In non-test environments, or when there is no `pauseOn` registered, this will return the `yieldable` directly.\n\n#### `ember-pausable-test/test-support`\n\n- `pauseOn(tokenName: String)`\n  This regsiters a pause to happen when a corresponding `pausable` is reached in the code.\n\n  This method returns a `PauseToken`.\n\n- `PauseToken`\n  - `resume()`\n    This will resolve the promise that is pausing the promise chain.\n\n  - `awaitPause()`\n    This returns a promise that will resolve the next time the corresponding `pausable()` block is hit.\n\n  - `throwException()`\n    This will cause the paused promise to reject, instead of resolve.\n\n### Configuration\n\nExperimental support for unwrappping/removing `pausable()` calls in non-test builds can be used by modifying your `ember-cli-build.js` file:\n\n```js\nconst app = new EmberApp({\n  'ember-pausable-test': {\n    strip: true\n  }\n});\n```\n\n## Collaborating\n--------\n\n### Running\n\n* `ember serve`\n* Visit your app at [http://localhost:4200](http://localhost:4200).\n\n### Running Tests\n\n* `yarn test` (Runs `ember try:each` to test your addon against multiple Ember versions)\n* `ember test`\n* `ember test --server`\n\n### Building\n\n* `ember build`\n\nFor more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).\n\n### Releasing\n\n* `ember release {--minor, --major, --patch}`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmovableink%2Fember-pausable-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmovableink%2Fember-pausable-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmovableink%2Fember-pausable-test/lists"}