{"id":15533727,"url":"https://github.com/rwjblue/ember-test-friendly-error-handler","last_synced_at":"2025-04-14T22:10:47.025Z","repository":{"id":46369014,"uuid":"105330052","full_name":"rwjblue/ember-test-friendly-error-handler","owner":"rwjblue","description":"Build testable error handlers that don't throw in production...","archived":false,"fork":false,"pushed_at":"2024-09-19T17:13:04.000Z","size":1395,"stargazers_count":16,"open_issues_count":17,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T11:50:11.761Z","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/rwjblue.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.MD","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-09-30T01:14:40.000Z","updated_at":"2025-04-09T10:12:13.000Z","dependencies_parsed_at":"2024-10-20T13:48:53.023Z","dependency_job_id":null,"html_url":"https://github.com/rwjblue/ember-test-friendly-error-handler","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwjblue%2Fember-test-friendly-error-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwjblue%2Fember-test-friendly-error-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwjblue%2Fember-test-friendly-error-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwjblue%2Fember-test-friendly-error-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rwjblue","download_url":"https://codeload.github.com/rwjblue/ember-test-friendly-error-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968914,"owners_count":21191162,"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-10-02T11:39:42.705Z","updated_at":"2025-04-14T22:10:46.994Z","avatar_url":"https://github.com/rwjblue.png","language":"JavaScript","funding_links":[],"categories":["Packages"],"sub_categories":["Testing"],"readme":"# ember-test-friendly-error-handler\n\nIn production, you often want to catch certain types of errors such as network errors (e.g. `myModel.save().catch(() =\u003e this.showNetworkFailureMessage())`) however these kinds of generic catch handlers can wreak havoc on your tests.  In tests, _most_ of the time you want these uncaught errors to _actually_ fail your tests unless explicitly testing the generic catch handler behaviors (e.g. `this.showNetworkFailureMessage`).\n\n## Installation\n\n    ember install ember-test-friendly-error-handler\n\n## Usage\n\nIn your application code you would import the error handler generator, and invoke it with a descriptive label and your callback.\n\n### Ember.onerror\n\n`Ember.onerror` is a hook that is invoked when an error is thrown by any code\nwithin the Ember run loop (e.g. `{{action}}`'s, component event methods, model\nhooks, etc). In practice, this is nearly all of your application code.\n`Ember.onerror` has the ability to \"swallow\" errors by handling them without\nrethrowing, and ultimately making the failure scenario impossible to detect\nwhile testing.\n\nIt is common for applications to leverage `Ember.onerror` to do error reporting\nand attempt to gracefully handle errors thrown within the application, and when\npossible prevent those errors from bubbling out and causing issues with the\nrunning application (or providing more detailed information when they do impact\nthe app).\n\nWithout something like `ember-test-friendly-error-handler`, applications that\nimplement `Ember.onerror` either have to replicate this addon's behavior, or are\nunable to properly test both the \"production\" mode (eg error swallowing) and\ndevelopment/testing mode (eg re-throw errors to make them possible to track down\nand fix).\n\nHere is how an application might set this up:\n\n```js\n// app/app.js\nimport Ember from 'ember';\nimport buildErrorHandler from 'ember-test-friendly-error-handler';\n\nEmber.onerror = buildErrorHandler('Ember.onerror', (reason) =\u003e {\n  reportErrorToService(reason);\n  // whatever else you might want here...\n});\n// ...existing `app/app.js` content goes here...\n```\n\n### Promises\n\nTo generate a promise rejection handler (aka `.catch` handler) you might do something like:\n\n```js\nimport buildErrorHandler from 'ember-test-friendly-error-handler';\n\n// ... snip ...\nmyModel.save()\n  .catch(buildErrorHandler('save-my-model', () =\u003e this.showNetworkFailureMessage()));\n```\n\n### Testing\n\nWhen you need to test the generic handler behavior (`this.showNetworkFailureMessage()` above), you need to disable the automatic error re-throwing behavior that `ember-test-friendly-error-handler` provides you so that your test more closely resembles your production environment.\n\nA test that does this might look like:\n\n```js\nimport { module, test } from 'qunit';\nimport { \n  squelchErrorHandlerFor,\n  unsquelchAllErrorHandlers\n} from 'ember-test-friendly-error-handler';\n\nmodule('some good description', {\n  afterEach() {\n    unsquelchAllErrorHandlers();\n  }\n});\n\ntest('network failure message is displayed', function(assert) {\n  squelchErrorHandlerFor('save-my-model');\n\n  triggerNetworkFailure();         // ⚡️\n  return triggerModelSave()\n    .then(() =\u003e {\n      assertNetworkFailureShown(); // 😼\n    });\n});\n```\n\n## API\n\nThe following interface describes the `ember-test-friendly-error-handler` module's API:\n\n```ts\nexport default function(label: string, callback: Function): Function;\n\n// the following are only present when testing\nexport function squelchErrorHandlerFor(label: string): void;\nexport function unsquelchAllErrorHandlers(): void;\n```\n\n## Contributing\n\n### Installation\n\n* `git clone \u003crepository-url\u003e` this repository\n* `cd ember-test-friendly-error-handler`\n* `npm install`\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* `npm 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwjblue%2Fember-test-friendly-error-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frwjblue%2Fember-test-friendly-error-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwjblue%2Fember-test-friendly-error-handler/lists"}