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

Commit b7fdabc

Browse files
matskoIgorMinar
authored andcommitted
feat(ngMock): support delay limit for $timeout.flush
1 parent 258cae8 commit b7fdabc

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/ngMock/angular-mocks.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1487,9 +1487,11 @@ angular.mock.$TimeoutDecorator = function($delegate, $browser) {
14871487
* @description
14881488
*
14891489
* Flushes the queue of pending tasks.
1490+
*
1491+
* @param {number=} delay maximum timeout amount to flush up until
14901492
*/
1491-
$delegate.flush = function() {
1492-
$browser.defer.flush();
1493+
$delegate.flush = function(delay) {
1494+
$browser.defer.flush(delay);
14931495
};
14941496

14951497
/**

test/ngMock/angular-mocksSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,20 @@ describe('ngMock', function() {
351351
$timeout.flush();
352352
expect(function() {$timeout.verifyNoPendingTasks();}).not.toThrow();
353353
}));
354+
355+
356+
it('should check against the delay if provided within timeout', inject(function($timeout) {
357+
$timeout(noop, 100);
358+
$timeout.flush(100);
359+
expect(function() {$timeout.verifyNoPendingTasks();}).not.toThrow();
360+
361+
$timeout(noop, 1000);
362+
$timeout.flush(100);
363+
expect(function() {$timeout.verifyNoPendingTasks();}).toThrow();
364+
365+
$timeout.flush(900);
366+
expect(function() {$timeout.verifyNoPendingTasks();}).not.toThrow();
367+
}));
354368
});
355369

356370

0 commit comments

Comments
 (0)