mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-17 11:11:05 +00:00
feat(ngMock): support delay limit for $timeout.flush
This commit is contained in:
parent
258cae83dc
commit
b7fdabc4bf
2 changed files with 18 additions and 2 deletions
6
src/ngMock/angular-mocks.js
vendored
6
src/ngMock/angular-mocks.js
vendored
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
14
test/ngMock/angular-mocksSpec.js
vendored
14
test/ngMock/angular-mocksSpec.js
vendored
|
|
@ -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();
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue