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

fakeAsync doesn't work #65

Closed
vvasabi opened this issue Aug 16, 2017 · 15 comments
Closed

fakeAsync doesn't work #65

vvasabi opened this issue Aug 16, 2017 · 15 comments

Comments

@vvasabi
Copy link

vvasabi commented Aug 16, 2017

Steps to reproduce:

  1. Clone this repo.
  2. Run yarn and yarn jest and note that the fakeAsync test fails

Note that yarn test, which uses Karma, passes.

@correasebastian
Copy link

any update here? any clue?

@thymikee
Copy link
Owner

Haven't tested this yet, but I remember fakeAsync worked for me.

@correasebastian
Copy link

@thymikee fakeAsync is doing its job flushing promises, but looks like is having hard time flushing timers, not sure why. but this is an example too

https://github.com/correasebastian/angular4-jest.git

@Waldo000000
Copy link

Waldo000000 commented Sep 25, 2017

Alternative repro steps @thymikee:

  1. Clone the example project (https://github.com/thymikee/jest-preset-angular/tree/master/example)
  2. Add the following spec to the project (copied directly from https://angular.io/api/core/testing/fakeAsync):
describe('this test', () => {
  it('looks async but is synchronous', <any>fakeAsync((): void => {
       let flag = false;
       setTimeout(() => { flag = true; }, 100);
       expect(flag).toBe(false);
       tick(50);
       expect(flag).toBe(false);
       tick(50);
       expect(flag).toBe(true);
     }));
});
  1. Upgrade zone.js from 0.8.10 to 0.8.11: yarn upgrade zone.js@0.8.11 (same behavior seen for latest zone.js version, i.e. 0.8.17)
  2. yarn test -- fails

Note that the same test (with the same dependencies) passes when using webpack + karma + Chrome headless.

@alonewarrior
Copy link

I'm having this same issue, my tests are failing because I'm requiring the use of a setTimeout to get certain behavior in the UI and these behaviors aren't being picked up by Jest until after the test has failed.

@thymikee
Copy link
Owner

I won't be able to verify it in following days, would appreciate some help on this in the meantime.

@thymikee
Copy link
Owner

thymikee commented Oct 1, 2017

Thanks @Waldo000000, I've confirmed it works with zone 0.8.10, but breaks since 0.8.11. I've also been able to track the change, which I think is a bug, but who knows.

I've asked about that in the relevant PR which introduced the change. Any help on this appreciated.

Temporary solution: lock down zone.js to 0.8.10

@thymikee
Copy link
Owner

thymikee commented Oct 2, 2017

I have a fix for that, which involves using newer version of jsdom, which means custom Jest environment. So I'll release it as a major version, since we'll drop Node 4 support (which will be dropped in Jest in couple of months anyway because it reaches its EOL).

@thymikee
Copy link
Owner

thymikee commented Oct 2, 2017

Hey folks, I've just released v4.0.0-alpha.1, can you give it a try with the zone.js >=0.8.11?

@vvasabi
Copy link
Author

vvasabi commented Oct 2, 2017

The fakeAsync test now passes in my test repo. Thank you very much! 🎉

@tkstang
Copy link

tkstang commented Jan 13, 2018

I'm using jest-preset-angular@5.0 and zone@0.8.2 and fakeAsync still fails for me

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 13, 2018

@tkstang I'm using jest-preset-angualr@5.0 and zone@0.8.19, fakeAsync works fine for me. Can you try updating zone ?

@tkstang
Copy link

tkstang commented Jan 13, 2018

0.8.20 is more up to date than 0.8.19 is it not?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 13, 2018

I haven't tried 0.8.20 yet but fakeAsync works for me at 0.8.19. Perhaps you can try 0.8.19 1st to see

@maxime1992
Copy link
Contributor

maxime1992 commented Mar 1, 2019

Hi, I'm currently facing the exact same issue with "zone.js": "0.8.29" and "jest": "24.1.0", "jest-preset-angular": "6.0.2". Any idea how to solve that?

My test is broken and then it ends up with

Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

@thymikee might be worth reopening the issue as it seems I'm not the only one recently to have that issue

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

No branches or pull requests

8 participants