Fixed bug where multiple calls to jasmine.Clock.useMock cause multiple tear downs
This commit is contained in:
parent
6a9f74e849
commit
9c8180d8d0
|
@ -409,6 +409,11 @@ jasmine.createSpyObj = function(baseName, methodNames) {
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All parameters are pretty-printed and concatenated together, then written to the current spec's output.
|
||||||
|
*
|
||||||
|
* Be careful not to leave calls to <code>jasmine.log</code> in production code.
|
||||||
|
*/
|
||||||
jasmine.log = function() {
|
jasmine.log = function() {
|
||||||
var spec = jasmine.getEnv().currentSpec;
|
var spec = jasmine.getEnv().currentSpec;
|
||||||
spec.log.apply(spec, arguments);
|
spec.log.apply(spec, arguments);
|
||||||
|
@ -1817,6 +1822,11 @@ jasmine.Spec.prototype.results = function() {
|
||||||
return this.results_;
|
return this.results_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All parameters are pretty-printed and concatenated together, then written to the spec's output.
|
||||||
|
*
|
||||||
|
* Be careful not to leave calls to <code>jasmine.log</code> in production code.
|
||||||
|
*/
|
||||||
jasmine.Spec.prototype.log = function() {
|
jasmine.Spec.prototype.log = function() {
|
||||||
return this.results_.log(arguments);
|
return this.results_.log(arguments);
|
||||||
};
|
};
|
||||||
|
@ -2180,9 +2190,9 @@ jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMil
|
||||||
funcToRun.funcToCall();
|
funcToRun.funcToCall();
|
||||||
if (funcToRun.recurring) {
|
if (funcToRun.recurring) {
|
||||||
this.scheduleFunction(funcToRun.timeoutKey,
|
this.scheduleFunction(funcToRun.timeoutKey,
|
||||||
funcToRun.funcToCall,
|
funcToRun.funcToCall,
|
||||||
funcToRun.millis,
|
funcToRun.millis,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
}
|
}
|
||||||
|
@ -2226,10 +2236,12 @@ jasmine.Clock = {
|
||||||
},
|
},
|
||||||
|
|
||||||
useMock: function() {
|
useMock: function() {
|
||||||
var spec = jasmine.getEnv().currentSpec;
|
if (!jasmine.Clock.isInstalled()) {
|
||||||
spec.after(jasmine.Clock.uninstallMock);
|
var spec = jasmine.getEnv().currentSpec;
|
||||||
|
spec.after(jasmine.Clock.uninstallMock);
|
||||||
|
|
||||||
jasmine.Clock.installMock();
|
jasmine.Clock.installMock();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
installMock: function() {
|
installMock: function() {
|
||||||
|
@ -2237,6 +2249,7 @@ jasmine.Clock = {
|
||||||
},
|
},
|
||||||
|
|
||||||
uninstallMock: function() {
|
uninstallMock: function() {
|
||||||
|
jasmine.log("uninstall")
|
||||||
jasmine.Clock.assertInstalled();
|
jasmine.Clock.assertInstalled();
|
||||||
jasmine.Clock.installed = jasmine.Clock.real;
|
jasmine.Clock.installed = jasmine.Clock.real;
|
||||||
},
|
},
|
||||||
|
@ -2249,11 +2262,15 @@ jasmine.Clock = {
|
||||||
},
|
},
|
||||||
|
|
||||||
assertInstalled: function() {
|
assertInstalled: function() {
|
||||||
if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) {
|
if (!jasmine.Clock.isInstalled()) {
|
||||||
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
|
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isInstalled: function() {
|
||||||
|
return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer;
|
||||||
|
},
|
||||||
|
|
||||||
installed: null
|
installed: null
|
||||||
};
|
};
|
||||||
jasmine.Clock.installed = jasmine.Clock.real;
|
jasmine.Clock.installed = jasmine.Clock.real;
|
||||||
|
@ -2287,7 +2304,7 @@ jasmine.getGlobal().clearInterval = function(timeoutKey) {
|
||||||
if (jasmine.Clock.installed.clearTimeout.apply) {
|
if (jasmine.Clock.installed.clearTimeout.apply) {
|
||||||
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
|
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
|
||||||
} else {
|
} else {
|
||||||
return jasmine.Clock.installed.clearInterval(timeoutKey);
|
return jasmine.Clock.installed.clearInterval(timeoutKey);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2296,5 +2313,5 @@ jasmine.version_= {
|
||||||
"major": 0,
|
"major": 0,
|
||||||
"minor": 11,
|
"minor": 11,
|
||||||
"build": 0,
|
"build": 0,
|
||||||
"revision": 1277253997
|
"revision": 1277316068
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
<script type="text/javascript" src="suites/ExceptionsSpec.js"></script>
|
<script type="text/javascript" src="suites/ExceptionsSpec.js"></script>
|
||||||
<script type="text/javascript" src="suites/JsApiReporterSpec.js"></script>
|
<script type="text/javascript" src="suites/JsApiReporterSpec.js"></script>
|
||||||
<script type="text/javascript" src="suites/MatchersSpec.js"></script>
|
<script type="text/javascript" src="suites/MatchersSpec.js"></script>
|
||||||
|
<script type="text/javascript" src="suites/MockClockSpec.js"></script>
|
||||||
<script type="text/javascript" src="suites/MultiReporterSpec.js"></script>
|
<script type="text/javascript" src="suites/MultiReporterSpec.js"></script>
|
||||||
<script type="text/javascript" src="suites/NestedResultsSpec.js"></script>
|
<script type="text/javascript" src="suites/NestedResultsSpec.js"></script>
|
||||||
<script type="text/javascript" src="suites/PrettyPrintSpec.js"></script>
|
<script type="text/javascript" src="suites/PrettyPrintSpec.js"></script>
|
||||||
|
|
|
@ -31,4 +31,8 @@ describe("MockClock", function () {
|
||||||
expect(interval).toEqual(2);
|
expect(interval).toEqual(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("shouldn't complain if you call jasmine.Clock.useMock() more than once", function() {
|
||||||
|
jasmine.Clock.useMock();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,9 +64,9 @@ jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMil
|
||||||
funcToRun.funcToCall();
|
funcToRun.funcToCall();
|
||||||
if (funcToRun.recurring) {
|
if (funcToRun.recurring) {
|
||||||
this.scheduleFunction(funcToRun.timeoutKey,
|
this.scheduleFunction(funcToRun.timeoutKey,
|
||||||
funcToRun.funcToCall,
|
funcToRun.funcToCall,
|
||||||
funcToRun.millis,
|
funcToRun.millis,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
}
|
}
|
||||||
|
@ -110,10 +110,12 @@ jasmine.Clock = {
|
||||||
},
|
},
|
||||||
|
|
||||||
useMock: function() {
|
useMock: function() {
|
||||||
var spec = jasmine.getEnv().currentSpec;
|
if (!jasmine.Clock.isInstalled()) {
|
||||||
spec.after(jasmine.Clock.uninstallMock);
|
var spec = jasmine.getEnv().currentSpec;
|
||||||
|
spec.after(jasmine.Clock.uninstallMock);
|
||||||
|
|
||||||
jasmine.Clock.installMock();
|
jasmine.Clock.installMock();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
installMock: function() {
|
installMock: function() {
|
||||||
|
@ -121,6 +123,7 @@ jasmine.Clock = {
|
||||||
},
|
},
|
||||||
|
|
||||||
uninstallMock: function() {
|
uninstallMock: function() {
|
||||||
|
jasmine.log("uninstall")
|
||||||
jasmine.Clock.assertInstalled();
|
jasmine.Clock.assertInstalled();
|
||||||
jasmine.Clock.installed = jasmine.Clock.real;
|
jasmine.Clock.installed = jasmine.Clock.real;
|
||||||
},
|
},
|
||||||
|
@ -133,11 +136,15 @@ jasmine.Clock = {
|
||||||
},
|
},
|
||||||
|
|
||||||
assertInstalled: function() {
|
assertInstalled: function() {
|
||||||
if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) {
|
if (!jasmine.Clock.isInstalled()) {
|
||||||
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
|
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isInstalled: function() {
|
||||||
|
return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer;
|
||||||
|
},
|
||||||
|
|
||||||
installed: null
|
installed: null
|
||||||
};
|
};
|
||||||
jasmine.Clock.installed = jasmine.Clock.real;
|
jasmine.Clock.installed = jasmine.Clock.real;
|
||||||
|
@ -171,7 +178,7 @@ jasmine.getGlobal().clearInterval = function(timeoutKey) {
|
||||||
if (jasmine.Clock.installed.clearTimeout.apply) {
|
if (jasmine.Clock.installed.clearTimeout.apply) {
|
||||||
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
|
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
|
||||||
} else {
|
} else {
|
||||||
return jasmine.Clock.installed.clearInterval(timeoutKey);
|
return jasmine.Clock.installed.clearInterval(timeoutKey);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue