Skip to content

Commit

Permalink
Fix dynamic immediates handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitrySoshnikov committed Jun 9, 2015
1 parent fe26035 commit 5907134
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/lib/FakeTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ FakeTimers.prototype.runAllTimers = function() {
}

this._runTimerHandle(nextTimerHandle);
}

// Some of the immediate calls could be enqueued
// during the previous handling of the timers, we should
// run them as well.
if (this._immediates.length) {
this.runAllImmediates();
// Some of the immediate calls could be enqueued
// during the previous handling of the timers, we should
// run them as well.
if (this._immediates.length) {
this.runAllImmediates();
}
}

if (i === this._maxLoops) {
Expand All @@ -184,14 +184,13 @@ FakeTimers.prototype.runAllTimers = function() {

// Used to be called runTimersOnce
FakeTimers.prototype.runOnlyPendingTimers = function() {
this.runAllImmediates();
var timers = this._timers;
Object.keys(timers)
.sort(function(left, right) {
return timers[left].expiry - timers[right].expiry;
})
.forEach(this._runTimerHandle, this);

this._immediates.forEach(this._runImmediate, this);
};

// Use to be runTimersToTime
Expand Down
4 changes: 2 additions & 2 deletions src/lib/__tests__/FakeTimers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,18 +554,18 @@ describe('FakeTimers', function() {

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

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

'mock2',
'mock1',
Expand Down

0 comments on commit 5907134

Please sign in to comment.