diff options
| -rw-r--r-- | src/ngMock/angular-mocks.js | 30 | ||||
| -rw-r--r-- | test/ngMock/angular-mocksSpec.js | 15 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index aed67c29..e05e7a28 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -118,6 +118,22 @@ angular.mock.$Browser = function() { self.deferredFns.shift().fn(); } }; + + /** + * @name ngMock.$browser#defer.flushNext + * @methodOf ngMock.$browser + * + * @description + * Flushes next pending request and compares it to the provided delay + * + * @param {number=} expectedDelay the delay value that will be asserted against the delay of the next timeout function + */ + self.defer.flushNext = function(expectedDelay) { + var tick = self.deferredFns.shift(); + expect(tick.time).toEqual(expectedDelay); + tick.fn(); + }; + /** * @name ngMock.$browser#defer.now * @propertyOf ngMock.$browser @@ -1496,6 +1512,20 @@ angular.mock.$TimeoutDecorator = function($delegate, $browser) { /** * @ngdoc method + * @name ngMock.$timeout#flushNext + * @methodOf ngMock.$timeout + * @description + * + * Flushes the next timeout in the queue and compares it to the provided delay + * + * @param {number=} expectedDelay the delay value that will be asserted against the delay of the next timeout function + */ + $delegate.flushNext = function(expectedDelay) { + $browser.defer.flushNext(expectedDelay); + }; + + /** + * @ngdoc method * @name ngMock.$timeout#verifyNoPendingTasks * @methodOf ngMock.$timeout * @description diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 37bf001a..4d238891 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -365,6 +365,21 @@ describe('ngMock', function() { $timeout.flush(900); expect(function() {$timeout.verifyNoPendingTasks();}).not.toThrow(); })); + + + it('should assert against the delay value', inject(function($timeout) { + var count = 0; + var iterate = function() { + count++; + }; + + $timeout(iterate, 100); + $timeout(iterate, 123); + $timeout.flushNext(100); + expect(count).toBe(1); + $timeout.flushNext(123); + expect(count).toBe(2); + })); }); |
