Permalink
Browse files

a function created by setInterval which calls clearInterval for itsel…

…f actually stops
  • Loading branch information...
Charles Hansen & Jacob Maine
Charles Hansen & Jacob Maine committed Sep 30, 2011
1 parent 41f4960 commit 63d5af2e9657a27d4b6f2c10fbb937240ddeff5f
Showing with 29 additions and 6 deletions.
  1. +4 −3 lib/jasmine-core/jasmine.js
  2. +21 −0 spec/core/MockClockSpec.js
  3. +3 −2 src/core/mock-timeout.js
  4. +1 −1 src/version.js
@@ -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;
}
}
@@ -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) {
}
@@ -2472,5 +2473,5 @@ jasmine.version_= {
"major": 1,
"minor": 1,
"build": 0,
- "revision": 1315677058
+ "revision": 1317399768
};
View
@@ -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() {
View
@@ -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;
}
}
@@ -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) {
}
View
@@ -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.