ember-cli/ember-ajax

Using run.join not working with thrown error

bobisjan opened this issue · 0 comments

Hi,

I've encounter a never ending test with failed AJAX. When error is thrown (eq. not handled in the task), then run.join throws this error immediately and fails to continue with always() part, so the test never settles.

export default class extend Component {
  @service ajax;

  @task(function *() {
    yield this.ajax.request('/api/data');
  }) load;
}
<button {{on "click" (perform this.load)}}>
  load
</button>

{{#if this.load.last.error}}
  <span class="error">error</span>
{{/if}}
test('it displays error', async function(assert) {
  assert.expect(2);

  this.server.get('/api/data', () => new Mirage.Response(500));

  setupOnerror(error => {
    assert.ok(error);
  });

  await this.render(hbs`<Loader />`);

  await click('button');

  assert.equal(this.element.querySelector('.error').textContent, 'error');
});

I've switched from run.join to run.next locally and then test continues as I would expect, but I'm not sure if this is a good fix for this, because I'm not familiar with runloop 😔.

Thanks for any advice.

/cc @rwjblue