Skip to content

Calling tick() in fakeAsync zone does not call all async function. #10299

@kasiditi

Description

@kasiditi

I'm submitting a ...

[x] bug report
[ ] feature request
[ ] support request

Current behavior

I'm trying to do some polling-like logic with a test, so I use a fakeAsync with tick() in the Jasmine test. But calling tick() does not resolve all asynchronous functions that is created during passage tick time.

Expected/desired behavior

tick() function should also resolve all the asynchronous functions that is created and should be executed during that time.

Reproduction of the problem

Here is the sample test:

it('tick should behave correctly', fakeAsync(() => {
    let counter = 0;
    const runner = () => {
        counter++;
        if (counter < 10) {
            setTimeout(() => runner(), 10);
        }
    };
    runner();
    tick(10000);
    expect(counter).toEqual(10);
}));

The test failed with 2 errors:

  • Expected 2 to equal 10.
  • Error: 1 timer(s) still in the queue.

What is the expected behavior?

The test should passes.

Current workaround for me is to use

for (let i = 0; i < 10000; i++) tick(1);

instead, which seems weird to me.

Please tell us about your environment:

  • Angular version: 2.0.0-rc.4
  • Browser: [Firefox | Chrome]
  • Language: [TypeScript 1.8]

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testingIssues related to Angular testing features, such as TestBedarea: zonesIssues related to zone.js

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions