Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
a function created by setInterval which calls clearInterval for itsel…
…f actually stops
  • Loading branch information
Charles Hansen & Jacob Maine committed Sep 30, 2011
1 parent 41f4960 commit 63d5af2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/jasmine-core/jasmine.js
Expand Up @@ -2336,7 +2336,6 @@ jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMil
scheduledFunc.runAtMillis >= oldMillis &&
scheduledFunc.runAtMillis <= nowMillis) {
funcsToRun.push(scheduledFunc);
this.scheduledFunctions[timeoutKey] = jasmine.undefined;
}
}

Expand All @@ -2349,11 +2348,13 @@ jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMil
var funcToRun = funcsToRun[i];
this.nowMillis = funcToRun.runAtMillis;
funcToRun.funcToCall();
if (funcToRun.recurring) {
if (funcToRun.recurring && this.scheduledFunctions[funcToRun.timeoutKey] != jasmine.undefined) {
this.scheduleFunction(funcToRun.timeoutKey,
funcToRun.funcToCall,
funcToRun.millis,
true);
} else {
this.scheduledFunctions[funcToRun.timeoutKey] = jasmine.undefined;
}
} catch(e) {
}
Expand Down Expand Up @@ -2472,5 +2473,5 @@ jasmine.version_= {
"major": 1,
"minor": 1,
"build": 0,
"revision": 1315677058
"revision": 1317399768
};
21 changes: 21 additions & 0 deletions spec/core/MockClockSpec.js
Expand Up @@ -30,6 +30,27 @@ describe("MockClock", function () {
jasmine.Clock.tick(1);
expect(interval).toEqual(2);
});

describe("#clearInterval", function () {
var callCount, intervalId;
beforeEach(function() {
callCount = 0;
intervalId = setInterval(function() {
callCount++;
if (callCount > 1) { clearInterval(intervalId); }
}, 30000);
});

it("should prevent the interval function from being called", function() {
expect(callCount).toEqual(0);
jasmine.Clock.tick(30000);
expect(callCount).toEqual(1);
jasmine.Clock.tick(30000);
expect(callCount).toEqual(2);
jasmine.Clock.tick(30000);
expect(callCount).toEqual(2);
});
});
});

it("shouldn't complain if you call jasmine.Clock.useMock() more than once", function() {
Expand Down
5 changes: 3 additions & 2 deletions src/core/mock-timeout.js
Expand Up @@ -49,7 +49,6 @@ jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMil
scheduledFunc.runAtMillis >= oldMillis &&
scheduledFunc.runAtMillis <= nowMillis) {
funcsToRun.push(scheduledFunc);
this.scheduledFunctions[timeoutKey] = jasmine.undefined;
}
}

Expand All @@ -62,11 +61,13 @@ jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMil
var funcToRun = funcsToRun[i];
this.nowMillis = funcToRun.runAtMillis;
funcToRun.funcToCall();
if (funcToRun.recurring) {
if (funcToRun.recurring && this.scheduledFunctions[funcToRun.timeoutKey] != jasmine.undefined) {
this.scheduleFunction(funcToRun.timeoutKey,
funcToRun.funcToCall,
funcToRun.millis,
true);
} else {
this.scheduledFunctions[funcToRun.timeoutKey] = jasmine.undefined;
}
} catch(e) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
Expand Up @@ -2,5 +2,5 @@ jasmine.version_= {
"major": 1,
"minor": 1,
"build": 0,
"revision": 1315677058
"revision": 1317399768
};

0 comments on commit 63d5af2

Please sign in to comment.