From 2b5ce84fca7b41fca24707e163ec6af84bc12e83 Mon Sep 17 00:00:00 2001 From: Julie Date: Fri, 13 Sep 2013 12:47:05 -0700 Subject: feat($interval): add a service wrapping setInterval The $interval service simplifies creating and testing recurring tasks. This service does not increment $browser's outstanding request count, which means that scenario tests and Protractor tests will not timeout when a site uses a polling function registered by $interval. Provides a workaround for #2402. For unit tests, repeated tasks can be controlled using ngMock$interval's tick(), tickNext(), and tickAll() functions. --- test/ng/timeoutSpec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/ng/timeoutSpec.js') diff --git a/test/ng/timeoutSpec.js b/test/ng/timeoutSpec.js index 8de63bec..97c8448e 100644 --- a/test/ng/timeoutSpec.js +++ b/test/ng/timeoutSpec.js @@ -165,6 +165,20 @@ describe('$timeout', function() { })); + it('should cancel the promise', inject(function($timeout, log) { + var promise = $timeout(noop); + promise.then(function(value) { log('promise success: ' + value); }, + function(err) { log('promise error: ' + err); }, + function(note) { log('promise update: ' + note); }); + expect(log).toEqual([]); + + $timeout.cancel(promise); + $timeout.flush(); + + expect(log).toEqual(['promise error: canceled']); + })); + + it('should return true if a task was successfully canceled', inject(function($timeout) { var task1 = jasmine.createSpy('task1'), task2 = jasmine.createSpy('task2'), -- cgit v1.2.3