-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Async/await in model hooks fail in tests #15556
Comments
Here is a working twiddle to demonstrate this issue in a component. |
The work around for Seems legit to hedge that bet with an initializer like the example in the RFC, emberjs/rfcs#175 (comment) |
@pixelhandler Thanks for providing background on this - totally just helped me. |
@pixelhandler regenerator isn't available if your only targets are the latest browsers which means that overwriting the global promise class wont work 😢. Is there a workaround for that? One way that I can think of is to force add regenerator by dynamically adding an older browser to the targets if the env is test. The only issue with that is now your test env wont be the same as your prod env. |
I believe Eventually (hopefully) none of us will have to use the regenerator any more. It seems that in the long-term, we may need the global |
@offirgolan this issue is actually keeping us from targeting only modern browsers. I'm hoping the new testing setup in RFC #232 will surface this with more apps and maybe a better solution will show up. |
@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/ |
@pixelhandler no, not really. @rwjblue is writing about setting up your app and test suite to support async / await. This issue is about async / await promises not being fulfilled in tests since Ember has no knowledge of them. As stated before, this happens when you target only the latest browsers which have no need for regenerator. |
Thanks for sharing @pixelhandler ! Related to rwjblue's blog post - I've found that async/await already totally helps with tests! But it's not ready to be used inside our Ember app code yet: |
Hoping to kickstart more efforts to enable this, but we should probably track the actual issue over on emberjs/rfcs#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... |
Given a model hook that uses
async
/await
and callsEmber.set
after anawait
statement, this will fail in an acceptance test visiting that route, with anYou 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 emberjs/rfcs#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
window.Promise = Ember.RSVP.Promise;
. (you can add that e.g. totests/index.html
)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.The text was updated successfully, but these errors were encountered: