From 284de574358693372f3655201d2b7b05d35306c3 Mon Sep 17 00:00:00 2001 From: rodyhaddad Date: Sat, 28 Jun 2014 13:52:21 -0700 Subject: [PATCH] test($interval): add tests making sure $interval uses the methods from $window --- test/ng/intervalSpec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/ng/intervalSpec.js b/test/ng/intervalSpec.js index 59f62d962..3d5089f75 100644 --- a/test/ng/intervalSpec.js +++ b/test/ng/intervalSpec.js @@ -267,4 +267,25 @@ describe('$interval', function() { expect($interval.cancel()).toBe(false); })); }); + + describe('$window delegation', function() { + it('should use $window.setInterval instead of the global function', inject(function ($interval, $window) { + var setIntervalSpy = spyOn($window, 'setInterval'); + + $interval(noop, 1000); + expect(setIntervalSpy).toHaveBeenCalled(); + })); + + it('should use $window.clearInterval instead of the global function', inject(function ($interval, $window) { + var clearIntervalSpy = spyOn($window, 'clearInterval'); + + $interval(noop, 1000, 1); + $window.flush(1000); + expect(clearIntervalSpy).toHaveBeenCalled(); + + clearIntervalSpy.reset(); + $interval.cancel($interval(noop, 1000)); + expect(clearIntervalSpy).toHaveBeenCalled(); + })); + }); });