mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-19 08:00:23 +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
|
||||
*
|
||||
* 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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
14
test/ngMock/angular-mocksSpec.js
vendored
14
test/ngMock/angular-mocksSpec.js
vendored
|
|
@ -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();
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue