mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-20 00:10:26 +00:00
revert: fix(mocks): $timeout#flush should not update time when empty
This reverts commit 42af8eada2.
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.
This commit is contained in:
parent
0f56cfdd13
commit
70b44ad32a
2 changed files with 4 additions and 22 deletions
9
src/ngMock/angular-mocks.js
vendored
9
src/ngMock/angular-mocks.js
vendored
|
|
@ -105,17 +105,16 @@ angular.mock.$Browser = function() {
|
|||
*/
|
||||
self.defer.flush = function(delay) {
|
||||
var flushedSomething = false;
|
||||
now = self.defer.now;
|
||||
|
||||
if (angular.isDefined(delay)) {
|
||||
now += delay;
|
||||
self.defer.now += delay;
|
||||
} else {
|
||||
if (self.deferredFns.length) {
|
||||
now = self.deferredFns[self.deferredFns.length-1].time;
|
||||
self.defer.now = self.deferredFns[self.deferredFns.length-1].time;
|
||||
}
|
||||
}
|
||||
|
||||
while (self.deferredFns.length && self.deferredFns[0].time <= now) {
|
||||
while (self.deferredFns.length && self.deferredFns[0].time <= self.defer.now) {
|
||||
flushedSomething = true;
|
||||
self.deferredFns.shift().fn();
|
||||
}
|
||||
|
|
@ -127,8 +126,6 @@ angular.mock.$Browser = function() {
|
|||
throw Error('No deferred tasks with delay up to ' + delay + 'ms to be flushed!')
|
||||
}
|
||||
}
|
||||
|
||||
self.defer.now = now;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
17
test/ngMock/angular-mocksSpec.js
vendored
17
test/ngMock/angular-mocksSpec.js
vendored
|
|
@ -404,7 +404,7 @@ describe('ngMock', function() {
|
|||
expect(function() {$timeout.flush(100);}).toThrow();
|
||||
expect(log).toEqual(['t1']);
|
||||
|
||||
$timeout.flush(1000);
|
||||
$timeout.flush(900);
|
||||
expect(log).toEqual(['t1', 't2']);
|
||||
expect(function() {$timeout.flush();}).toThrow();
|
||||
});
|
||||
|
|
@ -425,21 +425,6 @@ describe('ngMock', function() {
|
|||
});
|
||||
|
||||
|
||||
it('should not update the current time if an exception is thrown during a flush', function() {
|
||||
$timeout(log.fn('t1'), 100);
|
||||
$timeout(log.fn('t2'), 101);
|
||||
|
||||
expect(function() { $timeout.flush(90); }).toThrow();
|
||||
expect(function() { $timeout.flush(90); }).toThrow();
|
||||
|
||||
$timeout.flush(100);
|
||||
expect(log).toEqual(['t1']);
|
||||
|
||||
$timeout.flush(1);
|
||||
expect(log).toEqual(['t1', 't2']);
|
||||
});
|
||||
|
||||
|
||||
describe('verifyNoPendingTasks', function() {
|
||||
|
||||
it('should throw an exception when not flushed', function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue