diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index e5aeb993..534553f8 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1324,13 +1324,16 @@ getJasmineRequireObj().clearStack = function(j$) { if (global && global.process && j$.isFunction_(global.process.nextTick)) { return global.process.nextTick; } else if (j$.isFunction_(global.setImmediate)) { - return global.setImmediate; + var realSetImmediate = global.setImmediate; + return function(fn) { + realSetImmediate(fn); + }; } else if (!j$.util.isUndefined(global.MessageChannel)) { return messageChannelImpl(global); - } else if (j$.isFunction_(global.setTimeout)) { + } else { var realSetTimeout = global.setTimeout; return function clearStack(fn) { - realSetTimeout(fn, 0); + Function.prototype.apply.apply(realSetTimeout, [global, [fn, 0]]); }; } } diff --git a/spec/core/ClearStackSpec.js b/spec/core/ClearStackSpec.js index 4630d36e..8ad6277d 100644 --- a/spec/core/ClearStackSpec.js +++ b/spec/core/ClearStackSpec.js @@ -1,12 +1,6 @@ describe("ClearStack", function() { it("works in an integrationy way", function(done) { - var global = { - setTimeout: typeof setTimeout === 'undefined' ? undefined : setTimeout, - setImmediate: typeof setImmediate === 'undefined' ? undefined : setImmediate, - MessageChannel: typeof MessageChannel === 'undefined' ? undefined : MessageChannel, - process: typeof process === 'undefined' ? undefined : process - }, - clearStack = jasmineUnderTest.getClearStack(global); + var clearStack = jasmineUnderTest.getClearStack(jasmineUnderTest.getGlobal()); clearStack(function() { done(); diff --git a/spec/core/integration/EnvSpec.js b/spec/core/integration/EnvSpec.js index 4bead625..ecc6cb9a 100644 --- a/spec/core/integration/EnvSpec.js +++ b/spec/core/integration/EnvSpec.js @@ -940,8 +940,8 @@ describe("Env integration", function() { env.addReporter(reporter); jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 1290; - env.beforeAll(function(done) { - jasmine.clock().tick(1290); + env.beforeAll(function(innerDone) { + jasmine.clock().tick(1291); }); env.it("spec that will be failed", function() { @@ -981,6 +981,7 @@ describe("Env integration", function() { clock.tick(6); expect(true).toEqual(true); innerDone(); + jasmine.clock().tick(1); }); env.execute(); @@ -1007,10 +1008,12 @@ describe("Env integration", function() { env.afterAll(function(innerDone) { jasmine.clock().tick(3001); innerDone(); + jasmine.clock().tick(1); }); }); env.execute(); + jasmine.clock().tick(1); }); it('should wait a custom interval before reporting async functions that fail to call done', function(done) { @@ -1132,6 +1135,7 @@ describe("Env integration", function() { innerDone(); }, 1); jasmine.clock().tick(1); + jasmine.clock().tick(1); }); env.it('specifies a message', function(innerDone) { @@ -1140,6 +1144,7 @@ describe("Env integration", function() { innerDone(); }, 1); jasmine.clock().tick(1); + jasmine.clock().tick(1); }); env.it('fails via the done callback', function(innerDone) { @@ -1147,6 +1152,7 @@ describe("Env integration", function() { innerDone.fail('done failed'); }, 1); jasmine.clock().tick(1); + jasmine.clock().tick(1); }); env.it('has a message from an Error', function(innerDone) { @@ -1155,6 +1161,7 @@ describe("Env integration", function() { innerDone(); }, 1); jasmine.clock().tick(1); + jasmine.clock().tick(1); }); }); diff --git a/src/core/ClearStack.js b/src/core/ClearStack.js index 06d11df6..224582b7 100644 --- a/src/core/ClearStack.js +++ b/src/core/ClearStack.js @@ -21,13 +21,16 @@ getJasmineRequireObj().clearStack = function(j$) { if (global && global.process && j$.isFunction_(global.process.nextTick)) { return global.process.nextTick; } else if (j$.isFunction_(global.setImmediate)) { - return global.setImmediate; + var realSetImmediate = global.setImmediate; + return function(fn) { + realSetImmediate(fn); + }; } else if (!j$.util.isUndefined(global.MessageChannel)) { return messageChannelImpl(global); - } else if (j$.isFunction_(global.setTimeout)) { + } else { var realSetTimeout = global.setTimeout; return function clearStack(fn) { - realSetTimeout(fn, 0); + Function.prototype.apply.apply(realSetTimeout, [global, [fn, 0]]); }; } }