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

Commit cfbe1a7

Browse files
committed
revert: fix($timeout): make $flush handle new $timeouts added in $timeout callbacks
This reverts commit 1e5d36d. Breaks tests at google, needs more investigation.
1 parent aa38ded commit cfbe1a7

File tree

2 files changed

+4
-40
lines changed

2 files changed

+4
-40
lines changed

src/ngMock/angular-mocks.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -106,29 +106,19 @@ angular.mock.$Browser = function() {
106106
* @param {number=} number of milliseconds to flush. See {@link #defer.now}
107107
*/
108108
self.defer.flush = function(delay) {
109-
var nextTime;
110-
111109
if (angular.isDefined(delay)) {
112-
// A delay was passed so compute the next time
113-
nextTime = self.defer.now + delay;
110+
self.defer.now += delay;
114111
} else {
115112
if (self.deferredFns.length) {
116-
// No delay was passed so set the next time so that it clears the deferred queue
117-
nextTime = self.deferredFns[self.deferredFns.length - 1].time;
113+
self.defer.now = self.deferredFns[self.deferredFns.length - 1].time;
118114
} else {
119-
// No delay passed, but there are no deferred tasks so flush - indicates an error!
120115
throw new Error('No deferred tasks to be flushed');
121116
}
122117
}
123118

124-
while (self.deferredFns.length && self.deferredFns[0].time <= nextTime) {
125-
// Increment the time and call the next deferred function
126-
self.defer.now = self.deferredFns[0].time;
119+
while (self.deferredFns.length && self.deferredFns[0].time <= self.defer.now) {
127120
self.deferredFns.shift().fn();
128121
}
129-
130-
// Ensure that the current time is correct
131-
self.defer.now = nextTime;
132122
};
133123

134124
self.$$baseHref = '/';

test/ngMock/angular-mocksSpec.js

+1-27
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,8 @@ describe('ngMock', function() {
296296
expect(counter).toBe(1);
297297

298298
$interval.flush(1000);
299-
expect(counter).toBe(2);
300299

301-
$interval.flush(2000);
302-
expect(counter).toBe(4);
300+
expect(counter).toBe(2);
303301
}));
304302

305303

@@ -694,30 +692,6 @@ describe('ngMock', function() {
694692
$timeout.flush(123);
695693
expect(count).toBe(2);
696694
}));
697-
698-
it('should resolve timeout functions following the timeline', inject(function($timeout) {
699-
var count1 = 0, count2 = 0;
700-
var iterate1 = function() {
701-
count1++;
702-
$timeout(iterate1, 100);
703-
};
704-
var iterate2 = function() {
705-
count2++;
706-
$timeout(iterate2, 150);
707-
};
708-
709-
$timeout(iterate1, 100);
710-
$timeout(iterate2, 150);
711-
$timeout.flush(150);
712-
expect(count1).toBe(1);
713-
expect(count2).toBe(1);
714-
$timeout.flush(50);
715-
expect(count1).toBe(2);
716-
expect(count2).toBe(1);
717-
$timeout.flush(400);
718-
expect(count1).toBe(6);
719-
expect(count2).toBe(4);
720-
}));
721695
});
722696

723697

0 commit comments

Comments
 (0)