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

Commit

Permalink
feat(ngMock): support delay limit for $timeout.flush
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko authored and IgorMinar committed Jul 26, 2013
1 parent 258cae8 commit b7fdabc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,9 +1487,11 @@ angular.mock.$TimeoutDecorator = function($delegate, $browser) {
* @description
*
* Flushes the queue of pending tasks.
*
* @param {number=} delay maximum timeout amount to flush up until
*/
$delegate.flush = function() {
$browser.defer.flush();
$delegate.flush = function(delay) {
$browser.defer.flush(delay);
};

/**
Expand Down
14 changes: 14 additions & 0 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,20 @@ describe('ngMock', function() {
$timeout.flush();
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();
}));
});


Expand Down

0 comments on commit b7fdabc

Please sign in to comment.