feat(ngMock): support delay limit for $timeout.flush

This commit is contained in:
Matias Niemelä 2013-07-23 23:45:21 -04:00 committed by Igor Minar
parent 258cae83dc
commit b7fdabc4bf
2 changed files with 18 additions and 2 deletions

View file

@ -1487,9 +1487,11 @@ angular.mock.$TimeoutDecorator = function($delegate, $browser) {
* @description * @description
* *
* Flushes the queue of pending tasks. * Flushes the queue of pending tasks.
*
* @param {number=} delay maximum timeout amount to flush up until
*/ */
$delegate.flush = function() { $delegate.flush = function(delay) {
$browser.defer.flush(); $browser.defer.flush(delay);
}; };
/** /**

View file

@ -351,6 +351,20 @@ describe('ngMock', function() {
$timeout.flush(); $timeout.flush();
expect(function() {$timeout.verifyNoPendingTasks();}).not.toThrow(); expect(function() {$timeout.verifyNoPendingTasks();}).not.toThrow();
})); }));
it('should check against the delay if provided within timeout', inject(function($timeout) {
$timeout(noop, 100);
$timeout.flush(100);
expect(function() {$timeout.verifyNoPendingTasks();}).not.toThrow();
$timeout(noop, 1000);
$timeout.flush(100);
expect(function() {$timeout.verifyNoPendingTasks();}).toThrow();
$timeout.flush(900);
expect(function() {$timeout.verifyNoPendingTasks();}).not.toThrow();
}));
}); });