Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($interval): call fn even if invokeApply is false #5903

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ng/interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ function $IntervalProvider() {
promise.then(null, null, fn);

promise.$$intervalId = setInterval(function tick() {
deferred.notify(iteration++);
if (!skipApply) {
deferred.notify(iteration++);
} else {
fn(iteration++);
}

if (count > 0 && iteration >= count) {
deferred.resolve(iteration);
Expand Down
6 changes: 5 additions & 1 deletion src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,11 @@ angular.mock.$IntervalProvider = function() {
promise.$$intervalId = nextRepeatId;

function tick() {
deferred.notify(iteration++);
if (!skipApply) {
deferred.notify(iteration++);
} else {
fn(iteration++);
}

if (count > 0 && iteration >= count) {
var fnIndex;
Expand Down
18 changes: 18 additions & 0 deletions test/ng/intervalSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ describe('$interval', function() {
}));


it('should still call the interval fn if invokeApply is false',
inject(function($interval, $rootScope, $window) {
var spy = jasmine.createSpy('invokeApply = false');

$interval(spy, 100, 0, false);
expect(spy).not.toHaveBeenCalled();

$window.flush(100);
expect(spy).toHaveBeenCalled();

$window.flush(100);
expect(spy.callCount).toBe(2);

$window.flush(100);
expect(spy.callCount).toBe(3);
}));


it('should allow you to specify the delay time', inject(function($interval, $window) {
var counter = 0;
$interval(function() { counter++; }, 123);
Expand Down
14 changes: 14 additions & 0 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,20 @@ describe('ngMock', function() {
expect(counterA).toEqual(4);
expect(counterB).toEqual(1);
}));

it('should work if invokeApply is set to false', inject(function($interval) {
var counter = 0;
$interval(function() { counter++; }, 100, 0, false);

$interval.flush(100);
expect(counter).toBe(1);

$interval.flush(100);
expect(counter).toBe(2);

$interval.flush(100);
expect(counter).toBe(3);
}));
});


Expand Down