aboutsummaryrefslogtreecommitdiffstats
path: root/src/ngMock/angular-mocks.js
diff options
context:
space:
mode:
authorMatias Niemelä2013-07-24 23:22:09 -0400
committerIgor Minar2013-07-26 08:57:25 -0700
commit462ed033d512ae94cb188efc9453de84ace4e17e (patch)
tree0ddf743c25207230ec15e79eeb89ad492e925dec /src/ngMock/angular-mocks.js
parentb7fdabc4bf2a9dd11a57f98c5229d834c4589bab (diff)
downloadangular.js-462ed033d512ae94cb188efc9453de84ace4e17e.tar.bz2
feat(ngMock): $timeout.flushNext can expect specific timeout delays
the $timeout mock's flush method allows flushing queued up requests but doesn't allow to for checking with what delay a task was queued up. flushNext flushes the next queued up task and can asserts the scheduled delay.
Diffstat (limited to 'src/ngMock/angular-mocks.js')
-rw-r--r--src/ngMock/angular-mocks.js30
1 files changed, 30 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