Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 70b44ad

Browse files
committed
revert: fix(mocks): $timeout#flush should not update time when empty
This reverts commit 42af8ea. This turned out to be a bad idea as it prevents us from moving the time forward and asserting that the component state didn't change due to the scheduled task executing too early.
1 parent 0f56cfd commit 70b44ad

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

src/ngMock/angular-mocks.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ angular.mock.$Browser = function() {
105105
*/
106106
self.defer.flush = function(delay) {
107107
var flushedSomething = false;
108-
now = self.defer.now;
109108

110109
if (angular.isDefined(delay)) {
111-
now += delay;
110+
self.defer.now += delay;
112111
} else {
113112
if (self.deferredFns.length) {
114-
now = self.deferredFns[self.deferredFns.length-1].time;
113+
self.defer.now = self.deferredFns[self.deferredFns.length-1].time;
115114
}
116115
}
117116

118-
while (self.deferredFns.length && self.deferredFns[0].time <= now) {
117+
while (self.deferredFns.length && self.deferredFns[0].time <= self.defer.now) {
119118
flushedSomething = true;
120119
self.deferredFns.shift().fn();
121120
}
@@ -127,8 +126,6 @@ angular.mock.$Browser = function() {
127126
throw Error('No deferred tasks with delay up to ' + delay + 'ms to be flushed!')
128127
}
129128
}
130-
131-
self.defer.now = now;
132129
};
133130

134131
/**

test/ngMock/angular-mocksSpec.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ describe('ngMock', function() {
404404
expect(function() {$timeout.flush(100);}).toThrow();
405405
expect(log).toEqual(['t1']);
406406

407-
$timeout.flush(1000);
407+
$timeout.flush(900);
408408
expect(log).toEqual(['t1', 't2']);
409409
expect(function() {$timeout.flush();}).toThrow();
410410
});
@@ -425,21 +425,6 @@ describe('ngMock', function() {
425425
});
426426

427427

428-
it('should not update the current time if an exception is thrown during a flush', function() {
429-
$timeout(log.fn('t1'), 100);
430-
$timeout(log.fn('t2'), 101);
431-
432-
expect(function() { $timeout.flush(90); }).toThrow();
433-
expect(function() { $timeout.flush(90); }).toThrow();
434-
435-
$timeout.flush(100);
436-
expect(log).toEqual(['t1']);
437-
438-
$timeout.flush(1);
439-
expect(log).toEqual(['t1', 't2']);
440-
});
441-
442-
443428
describe('verifyNoPendingTasks', function() {
444429

445430
it('should throw an exception when not flushed', function() {

0 commit comments

Comments
 (0)