Skip to content

Commit

Permalink
Make sure runAllTimers also clears all ticks (#3915)
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee authored and cpojer committed Jun 27, 2017
1 parent acc783a commit 113639b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/jest-util/src/__tests__/fake_timers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,21 @@ describe('FakeTimers', () => {
),
);
});

it('also clears ticks', () => {
const global = {process};
const timers = new FakeTimers(global, moduleMocker);
timers.useFakeTimers();

const fn = jest.genMockFn();
global.setTimeout(() => {
process.nextTick(fn);
}, 0);
expect(fn.mock.calls.length).toBe(0);

timers.runAllTimers();
expect(fn.mock.calls.length).toBe(1);
});
});

describe('runTimersToTime', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-util/src/fake_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ class FakeTimers {
if (this._immediates.length) {
this.runAllImmediates();
}

if (this._ticks.length) {
this.runAllTicks();
}
}

if (i === this._maxLoops) {
Expand Down

0 comments on commit 113639b

Please sign in to comment.