to mock your API calls (Mirage, Pretender, Polly.js, ...) • Use await waitFor() after a regular test helper without await (click, focus, ...) to wait for a loading state • Use await settled() to check the end state • Use defer() to avoid race conditions and speed up the tests
{}, 500); await click('button'); await render(hbs`<LikeButton!/>`); assert.dom('[data-test-error]') .hasText('whoops… that did not work!'); }); Where do we display this?
@task *likeTask() { let response = yield fetch('/like', { method: 'POST' }); if (!response.ok) { this.notifications.error( 'whoops… that did not work!' ); } } }
{ autoClear: true, }, }; if (environment !!=== 'test') { !// disable auto clearing so that we can !// manually clear the queue if needed ENV['ember-cli-notifications'].autoClear = false; } config/environment.js
@task *likeTask() { let response = yield fetch('/like', { method: 'POST' }); if (!response.ok) { this.notifications.error( 'whoops… that did not work!' ); } } } fetch can fail too!
function () { throw new TypeError( 'NetworkError when attempting to fetch resource.' ); }; await render(hbs`<LikeButton!/>`); await click('button'); assert.dom('[data-test-notification-message="error"]') .hasText('whoops… that did not work!'); });
function () { throw new TypeError( 'NetworkError when attempting to fetch resource.' ); }; await render(hbs`<LikeButton!/>`); await click('button'); assert.dom('[data-test-notification-message="error"]') .hasText('whoops… that did not work!'); }); needs to be reset after the test!
extends Component { @task *likeTask() { try { let response = yield fetch('/like', { method: 'POST' }); if (!response.ok) { throw new Error('HTTP request failed'); } } catch (error) { this.notifications.error('whoops… that did not work!'); Sentry.captureException(error); } } } do we want to send ALL errors to Sentry?