Use jasmine.DEFAULT_TIMEOUT_INTERVAL for async timeout
Allows a user to specify their desired timeout interval for async specs and change it on a per spec basis (for particularly slow specs, for example). As pointed out by @Eric-Wright in #422. [finishes #55996798]
This commit is contained in:
@@ -280,7 +280,7 @@ getJasmineRequireObj().Spec = function() {
|
|||||||
var timeout = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
|
var timeout = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
|
||||||
onException(new Error('timeout'));
|
onException(new Error('timeout'));
|
||||||
done();
|
done();
|
||||||
}, 10000]]);
|
}, j$.DEFAULT_TIMEOUT_INTERVAL]]);
|
||||||
|
|
||||||
var callDone = function() {
|
var callDone = function() {
|
||||||
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeout]]);
|
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeout]]);
|
||||||
|
|||||||
@@ -357,15 +357,19 @@ describe("Env integration", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("with a mock clock", function() {
|
describe("with a mock clock", function() {
|
||||||
|
var originalTimeout;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
originalTimeout = j$.DEFAULT_TIMEOUT_INTERVAL;
|
||||||
jasmine.getEnv().clock.install();
|
jasmine.getEnv().clock.install();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
jasmine.getEnv().clock.uninstall();
|
jasmine.getEnv().clock.uninstall();
|
||||||
|
j$.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not hang on async specs that forget to call done()", function(done) {
|
it("should wait a specified interval before failing specs haven't called done yet", function(done) {
|
||||||
var env = new j$.Env(),
|
var env = new j$.Env(),
|
||||||
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone" ]);
|
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone" ]);
|
||||||
|
|
||||||
@@ -375,10 +379,11 @@ describe("Env integration", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
|
j$.DEFAULT_TIMEOUT_INTERVAL = 8414;
|
||||||
|
|
||||||
env.it("async spec that will hang", function(underTestCallback) {
|
env.it("async spec that doesn't call done", function(underTestCallback) {
|
||||||
env.expect(true).toBeTruthy();
|
env.expect(true).toBeTruthy();
|
||||||
jasmine.getEnv().clock.tick(10000);
|
jasmine.getEnv().clock.tick(8414);
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute();
|
env.execute();
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ getJasmineRequireObj().Spec = function() {
|
|||||||
var timeout = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
|
var timeout = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
|
||||||
onException(new Error('timeout'));
|
onException(new Error('timeout'));
|
||||||
done();
|
done();
|
||||||
}, 10000]]);
|
}, j$.DEFAULT_TIMEOUT_INTERVAL]]);
|
||||||
|
|
||||||
var callDone = function() {
|
var callDone = function() {
|
||||||
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeout]]);
|
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeout]]);
|
||||||
|
|||||||
Reference in New Issue
Block a user