Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix runOnlyPendingTimers for setTimeout inside setImmediate
  • Loading branch information
thymikee committed Oct 5, 2017
commit 4bbce5c34121b40fb81acebf6cb863202b4edd9c
9 changes: 8 additions & 1 deletion packages/jest-util/src/__tests__/fake_timers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,19 +586,26 @@ describe('FakeTimers', () => {
runOrder.push('mock4');
});

global.setImmediate(function cb() {
runOrder.push('mock5');
global.setTimeout(cb, 400);
});

timers.runOnlyPendingTimers();
expect(runOrder).toEqual(['mock4', 'mock2', 'mock1', 'mock3']);
expect(runOrder).toEqual(['mock4', 'mock5', 'mock2', 'mock1', 'mock3']);

timers.runOnlyPendingTimers();
expect(runOrder).toEqual([
'mock4',
'mock5',
'mock2',
'mock1',
'mock3',

'mock2',
'mock1',
'mock3',
'mock5',
]);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-util/src/fake_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ export default class FakeTimers {
}

runOnlyPendingTimers() {
const timers = Object.assign({}, this._timers);
this._checkFakeTimers();
this._immediates.forEach(this._runImmediate, this);
const timers = this._timers;
Object.keys(timers)
.sort((left, right) => timers[left].expiry - timers[right].expiry)
.forEach(this._runTimerHandle, this);
Expand Down