You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(testing) Unable to do async-initialization in beforeEach-hook #9815
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
In my tests I use the beforeEach-Hook to create the component-fixture. This worked in the past but with the latest changes I'm unable to get that working again. Trying to do it like this:
Chrome 48.0.2564 (Linux 0.0.0) TaskList Component should call deleteTask when clicking the trash-bin FAILED Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Expected/desired behavior
beforeEach callback should wait for returned promises / should be able to work with done-function
What is the motivation / use case for changing the behavior?
being able to initialize the component under test in beforeEach-Hook
@katherinegould I tried it also, but that was not fixing it for me (karma 0.13.22 -> 1.1.0, karma-jasmine 0.3.8 -> 1.0.2, systemjs 0.19.26 -> 0.19.31)...
@cexbrayat@katherinegould Both of your workarounds don't fix it for me. Deleting system-polyfills changes nothing and I already have karma-jasmine in my devDependencies... :/
Which way do you do the initialization? Using async or using done? On my side about 1 in 10 test-runs pass when using async, but I'm quite sure that this is only by accident, as sometimes the tcb.createAsync finishes before the actual test-run starts.
@choeller Using async, pretty much as in your first example. I migrated the 300 unit tests of my ebook to rc.4, and then a few hundreds in other projects,all clear using async if I comment system-polyfill in karma conf...
@cexbrayat woah - awesome! commenting out system-polyfill actually does solve my problem too... I just introduced another bug while trying out stuff... that's quite weird.
I had some tests working this way and others failing. I narrowed it down to the components with styleUrls failed and the ones with the styles defined in the component decorator didn't fail.
The order of polyfills unfortunately does matter - I believe we note this where we have examples, I'm not sure what else we can do. @choeller any place that documentation would have assisted you?
Activity
katherinegould commentedon Jul 5, 2016
+1
BenjaminRhys-Davies commentedon Jul 5, 2016
👍
cexbrayat commentedon Jul 6, 2016
Same here, but not in all my projects.
So, this is going to sound a bit weird, but I solved it by removing the
system-polyfills.jsin the Karma setup generated by angular-cli...katherinegould commentedon Jul 6, 2016
I've just managed to fix it by adding the
karma-jasminepackage to ourdevDependancies"karma-jasmine": "^0.3.6"cexbrayat commentedon Jul 6, 2016
@katherinegould I tried it also, but that was not fixing it for me (karma 0.13.22 -> 1.1.0, karma-jasmine 0.3.8 -> 1.0.2, systemjs 0.19.26 -> 0.19.31)...
choeller commentedon Jul 6, 2016
@cexbrayat @katherinegould Both of your workarounds don't fix it for me. Deleting system-polyfills changes nothing and I already have karma-jasmine in my devDependencies... :/
Which way do you do the initialization? Using
asyncor usingdone? On my side about 1 in 10 test-runs pass when usingasync, but I'm quite sure that this is only by accident, as sometimes thetcb.createAsyncfinishes before the actual test-run starts.cexbrayat commentedon Jul 6, 2016
@choeller Using
async, pretty much as in your first example. I migrated the 300 unit tests of my ebook to rc.4, and then a few hundreds in other projects,all clear usingasyncif I commentsystem-polyfillin karma conf...choeller commentedon Jul 6, 2016
@cexbrayat woah - awesome! commenting out
system-polyfillactually does solve my problem too... I just introduced another bug while trying out stuff... that's quite weird.Maybe @juliemr can shed some light on this?
katherinegould commentedon Jul 6, 2016
Strange that it works for me with
system-polyfillleft in.@choeller I'm using
asynctoo.choeller commentedon Jul 6, 2016
I just played around a little more and for me it works when I include
system-polyfillbeforezone.jsbut not the other way around...ok:
not ok:
obviously
system-polyfillsoverrides some async behaviour added byzone.jsjonnysamps commentedon Jul 6, 2016
I had some tests working this way and others failing. I narrowed it down to the components with
styleUrlsfailed and the ones with thestylesdefined in the component decorator didn't fail.Tests Pass:
Tests Failed:
meeroslav commentedon Jul 11, 2016
For me none of the above mentioned proposals worked with RC4. However, I did manage to solve it by simply removing async from tests.
This works every time:
This NEVER works:
Not sure what is keeping test (async on) active as body gets evaluated rather quickly.
dalamgir commentedon Jul 11, 2016
Tried this with rc4 does not seem to work
juliemr commentedon Jul 19, 2016
The order of polyfills unfortunately does matter - I believe we note this where we have examples, I'm not sure what else we can do. @choeller any place that documentation would have assisted you?
choeller commentedon Jul 19, 2016
@juliemr Ok, I see. I think the biggest problem is, that angular-cli currently does it "wrong". See https://github.com/angular/angular-cli/blob/master/addon/ng2/blueprints/ng2/files/config/karma.conf.js
Should I file an issue on this?
juliemr commentedon Jul 19, 2016
@choeller yes please!
fix(test) corrected order of loaded files
fix(test) corrected order of loaded files
choeller commentedon Jul 19, 2016
Ok, so I just created an PR for this (removed your name from commit message again ;))
fix(test) corrected order of loaded files
angular-automatic-lock-bot commentedon Sep 13, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.