Jest-preset-angular: fakeAsync doesn't work

Created on 16 Aug 2017  路  15Comments  路  Source: thymikee/jest-preset-angular

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.

Most helpful comment

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

All 15 comments

any update here? any clue?

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

@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

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 [email protected] (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.

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.

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

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

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).

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

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

I'm using [email protected] and [email protected] and fakeAsync still fails for me

@tkstang I'm using [email protected] and [email protected], fakeAsync works fine for me. Can you try updating zone ?

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

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

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

Was this page helpful?
0 / 5 - 0 ratings