Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict with async functions and Ember's run loop #1330

Closed
FrenchDilettante opened this issue Jun 15, 2018 · 4 comments
Closed

Conflict with async functions and Ember's run loop #1330

FrenchDilettante opened this issue Jun 15, 2018 · 4 comments
Labels

Comments

@FrenchDilettante
Copy link

Hi guys 👋

First time I open a ticket here, and also this issue is very confusing to me, so please bear with me while I try to make sense of it 🙏
I'm also not sure if this is purely because of ember-cli-mirage, or if this is an issue with qunit/ember-data. If that's the case, please point it out!

I managed to create a basic Ember repo to reproduce the error I got:
https://github.com/manudwarf/ember-cli-mirage-async

Here are the relevant snippets:

I started from this code:

  successPromise() {
    this.get('model').save()
      .then(() => this.get('model').set('name', 'New Name!'));
  },

Which works, and then I rewrote it using new Javascript async goodness:

  async failAsync() {
    await this.get('model').save();
    this.get('model').set('name', 'New Name!');
  },

But this fails in acceptance tests. However, if I use this code:

  async successAsync() {
    this.set('saving', true);
    await this.get('model').save();
    this.set('saving', false);
    this.get('model').set('name', 'New Name!');
  },

It all works fine.

Here is the acceptance test:

  test('fail with async', async function(assert) {
    await visit('/sample');
    await click('#fail-async');
    assert.ok(true);
  });

Here is the error that is thrown:

Error: Assertion Failed: You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in a run

This comes from the model.set(...) statement, more specifically this._internalModel.send('didSetProperty', ...), in the recordDidChange function.

Moreover, you'll notice the difference with set('saving', ...). This test case fails if I remove the <span> from the template:
https://github.com/manudwarf/ember-cli-mirage-async/blob/master/app/templates/components/sample-form.hbs

@samselikoff
Copy link
Collaborator

Not sure, will have to dig into it. Thanks for the repro!

@jelhan
Copy link
Contributor

jelhan commented Jul 6, 2018

Isn't this simply the autorun assertion by ember, which is not yet removed? emberjs/ember.js#16797 https://discuss.emberjs.com/t/readers-questions-why-does-ember-still-use-rsvp/14736

@samselikoff
Copy link
Collaborator

I upgrade Ember Data to 3.3.1 and that fixed the text. Looks like it was an ED bug!

@samselikoff
Copy link
Collaborator

Feel free to post if you have any more questions :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants