question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async/await in model hooks fail in tests

See original GitHub issue

Given a model hook that uses async/await and calls Ember.set after an await statement, this will fail in an acceptance test visiting that route, with an 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 error. This does not happen when rewriting this using Promises.

If I understand this correctly, the root issue seems to be that native Promises do not integrate into the Ember run loop, while RSVP.Promise do, and is the same as reported in #15240 and https://github.com/emberjs/rfcs/issues/175. But I thought creating this issue here would help others getting bitten by this to find this.

As reported elsewhere, a workaround is possible by

  • replacing the native Promise in tests with the RSVP one: window.Promise = Ember.RSVP.Promise;. (you can add that e.g. to tests/index.html)
  • making sure your targets.js is configured to make Babel transpile async/await. Using native async/await in e.g. Chrome does always lead to those failing tests.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pixelhandlercommented, Nov 3, 2017

@simonihmig @jrjohnson @caseywatts @offirgolan @alvincrespo Perhaps this post sheds some light on the considerations for running with async/await …

http://rwjblue.com/2017/10/30/async-await-configuration-adventure/

0reactions
rwjbluecommented, Nov 5, 2017

Hoping to kickstart more efforts to enable this, but we should probably track the actual issue over on https://github.com/emberjs/rfcs/issues/175 (which I think predates this issue a bit). I’ll try to chime in over there with a quick status update and lay out the game plan that @krisselden is coaching me on…

Read more comments on GitHub >

github_iconTop Results From Across the Web

For async tests and hooks, ensure "done()" is called
My test code is, I have the done call back but still getting the error to call the done(); it('remove existing subdocument', (done)...
Read more >
Testing Asynchronous Code - Jest
If the promise is rejected, the test will fail. For example, let's say that fetchData returns a promise that is supposed to resolve...
Read more >
Ember test with async await functions not working as intended
I am using ember-simple-auth with custom authenticator, which is pretty basic. Just sends login request to backend API, catching error when ...
Read more >
Testing asynchronous code - Japa tests runner
The async/await code reads linearly and is easy to reason. Let us share some of the ways you can use to convert callbacks,...
Read more >
Async waits in React Testing Library - Reflect.run
Handling when the API call returns with an error or timeout via Promise chaining or a try/catch block and async/await.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found