diff --git a/spec/suites/ReporterTest.js b/spec/suites/ReporterTest.js index 6743e84..4ceeccb 100644 --- a/spec/suites/ReporterTest.js +++ b/spec/suites/ReporterTest.js @@ -1,8 +1,16 @@ describe('jasmine.Reporter', function() { var env; + var fakeTimer; + beforeEach(function() { env = new jasmine.Env(); + + fakeTimer = new jasmine.FakeTimer(); + env.setTimeout = fakeTimer.setTimeout; + env.clearTimeout = fakeTimer.clearTimeout; + env.setInterval = fakeTimer.setInterval; + env.clearInterval = fakeTimer.clearInterval; }); it('should get called from the test runner', function() { @@ -49,6 +57,7 @@ describe('jasmine.Reporter', function() { var runner = env.currentRunner; runner.execute(); + fakeTimer.tick(0); expect(foo).toEqual(3); // 'foo was expected to be 3, was ' + foo); expect(bar).toEqual(2); // 'bar was expected to be 2, was ' + bar); diff --git a/spec/suites/RunnerTest.js b/spec/suites/RunnerTest.js index b31d6fb..78320eb 100644 --- a/spec/suites/RunnerTest.js +++ b/spec/suites/RunnerTest.js @@ -30,6 +30,7 @@ describe('RunnerTest', function() { }); env.currentRunner.execute(); + fakeTimer.tick(0); var runnerResults = env.currentRunner.getResults(); expect(runnerResults.totalCount).toEqual(2); @@ -56,7 +57,8 @@ describe('RunnerTest', function() { }); env.currentRunner.execute(); - + fakeTimer.tick(0); + var runnerResults = env.currentRunner.getResults(); expect(runnerResults.totalCount).toEqual(1); expect(runnerResults.passedCount).toEqual(0); @@ -64,7 +66,6 @@ describe('RunnerTest', function() { }); it('should roll up results from all specs', function() { - var env = new jasmine.Env(); env.describe('one suite description', function () { env.it('should be a test', function() { this.runs(function () { @@ -82,7 +83,8 @@ describe('RunnerTest', function() { }); env.currentRunner.execute(); - + fakeTimer.tick(0); + var results = env.currentRunner.getResults(); expect(results.totalCount).toEqual(2); expect(results.passedCount).toEqual(1); diff --git a/spec/suites/SpecRunningTest.js b/spec/suites/SpecRunningTest.js index 5a827eb..737d0cc 100644 --- a/spec/suites/SpecRunningTest.js +++ b/spec/suites/SpecRunningTest.js @@ -64,7 +64,8 @@ describe("jasmine spec running", function () { }); suite.execute(); - + fakeTimer.tick(0); + expect(specWithNoBody.description).toEqual('new spec'); expect(specWithExpectation.results.getItems().length).toEqual(1); // "Results aren't there after a spec was executed" @@ -116,6 +117,8 @@ describe("jasmine spec running", function () { expect(foo).toEqual(0); specWithRunsAndWaits.execute(); + fakeTimer.tick(0); + expect(foo).toEqual(1); fakeTimer.tick(500); expect(foo).toEqual(2); @@ -139,6 +142,7 @@ describe("jasmine spec running", function () { }); a_spec.execute(); + fakeTimer.tick(0); expect(a_spec.results.getItems().length).toEqual(1); // 'No call to waits(): Spec queue did not run all functions'; expect(a_spec.results.getItems()[0].passed).toEqual(true); // 'No call to waits(): Queued expectation failed'; @@ -159,6 +163,8 @@ describe("jasmine spec running", function () { }); a_spec.execute(); + fakeTimer.tick(0); + expect(a_spec.results.getItems().length).toEqual(0); fakeTimer.tick(500); @@ -218,7 +224,10 @@ describe("jasmine spec running", function () { yet_another_spec.execute(); - fakeTimer.tick(250); + //tick twice so that second runs gets eval'd first: mockClock bug? + fakeTimer.tick(100); + fakeTimer.tick(150); + expect(yet_another_spec.results.getItems().length).toEqual(1); expect(yet_another_spec.results.getItems()[0].passed).toEqual(false); @@ -353,6 +362,8 @@ describe("jasmine spec running", function () { }); suite.execute(); + fakeTimer.tick(0); + expect(log).toEqual("specafter2after1"); }); @@ -383,6 +394,8 @@ describe("jasmine spec running", function () { }); suite.execute(); + fakeTimer.tick(0); + expect(foo).toEqual(1); expect(bar).toEqual(0); @@ -415,6 +428,8 @@ describe("jasmine spec running", function () { }); suiteWithBefore.execute(); + fakeTimer.tick(0); + var suite = suiteWithBefore; expect(suite.beforeEachFunction); // "testBeforeAndAfterCallbacks: Suite's beforeEach was not defined"); expect(suite.getResults()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2"); @@ -442,6 +457,8 @@ describe("jasmine spec running", function () { }); suiteWithAfter.execute(); + fakeTimer.tick(0); + suite = suiteWithAfter; expect(suite.afterEach.length).toEqual(1); expect(suite.getResults()[0].passed()).toEqual(true); @@ -502,6 +519,8 @@ describe("jasmine spec running", function () { expect(baz).toEqual(0); expect(quux).toEqual(0); nested.execute(); + fakeTimer.tick(0); + expect(foo).toEqual(1); expect(bar).toEqual(1); expect(baz).toEqual(1); @@ -536,6 +555,8 @@ describe("jasmine spec running", function () { expect(reachedFirstWaitsFor).toEqual(false); waitsSuite.execute(); + fakeTimer.tick(0); + expect(reachedFirstWaitsFor).toEqual(true); expect(foo).toEqual(0); expect(reachedSecondWaitsFor).toEqual(false); @@ -618,6 +639,7 @@ describe("jasmine spec running", function () { expect(foo).toEqual(0); expect(bar).toEqual(0); suiteWithBefore.execute(); + fakeTimer.tick(0); expect(bar).toEqual(0); expect(foo).toEqual(1); @@ -659,6 +681,8 @@ describe("jasmine spec running", function () { expect(foo).toEqual(0); suiteWithAfter.execute(); + fakeTimer.tick(0); + expect(firstSpecHasRun).toEqual(true); expect(secondSpecHasRun).toEqual(false); @@ -794,6 +818,7 @@ describe("jasmine spec running", function () { }); suite.execute(); + fakeTimer.tick(0); expect(report).toEqual("firstsecond"); var suiteResults = suite.getResults(); @@ -832,6 +857,7 @@ describe("jasmine spec running", function () { }); suite.execute(); + fakeTimer.tick(0); expect(report).toEqual("firstsecondthird"); // "all tests should run"); //After each errors should not go in spec results because it confuses the count. @@ -898,7 +924,8 @@ describe("jasmine spec running", function () { }); env.execute(); - + fakeTimer.tick(0); + var expected = [ "outer beforeEach", @@ -1048,6 +1075,7 @@ describe("jasmine spec running", function () { }); suite.execute(); + fakeTimer.tick(0); expect(spec1Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: actual: xxx; expected: expected"); expect(spec1Matcher.matcherForSpec("expected")).toEqual("matcherForSpec: actual: xxx; expected: expected"); diff --git a/src/Queue.js b/src/Queue.js index 0751436..ade5c3d 100644 --- a/src/Queue.js +++ b/src/Queue.js @@ -1,4 +1,5 @@ -jasmine.Queue = function() { +jasmine.Queue = function(env) { + this.env = env; this.blocks = []; this.running = false; this.index = 0; @@ -37,13 +38,17 @@ jasmine.Queue.prototype.isRunning = function () { jasmine.Queue.prototype._next = function () { var self = this; - self.offset = 0; - self.index++; - if (self.index < self.blocks.length) { - self.blocks[self.index].execute(function () {self._next();}); - } else { - self.finish(); - } + self.env.setTimeout(function () { + self.offset = 0; + self.index++; + if (self.index < self.blocks.length) { + self.blocks[self.index].execute(function () { + self._next(); + }); + } else { + self.finish(); + } + }, 0); }; jasmine.Queue.prototype.finish = function () { diff --git a/src/Runner.js b/src/Runner.js index 95205f5..a3e99c4 100644 --- a/src/Runner.js +++ b/src/Runner.js @@ -7,7 +7,7 @@ jasmine.Runner = function(env) { var self = this; self.env = env; - self.queue = new jasmine.Queue(); + self.queue = new jasmine.Queue(env); }; jasmine.Runner.prototype.execute = function() { diff --git a/src/Spec.js b/src/Spec.js index 899b0c6..879671d 100644 --- a/src/Spec.js +++ b/src/Spec.js @@ -12,7 +12,7 @@ jasmine.Spec = function(env, suite, description) { spec.env = env; spec.suite = suite; spec.description = description; - spec.queue = new jasmine.Queue(); + spec.queue = new jasmine.Queue(env); spec.finished = false; spec.afterCallbacks = []; diff --git a/src/Suite.js b/src/Suite.js index 9a3a431..0523c1f 100644 --- a/src/Suite.js +++ b/src/Suite.js @@ -11,7 +11,7 @@ jasmine.Suite = function(env, description, specDefinitions, parentSuite) { var self = this; self.id = env.nextSuiteId_++; self.description = description; - self.queue = new jasmine.Queue(); + self.queue = new jasmine.Queue(env); self.parentSuite = parentSuite; self.env = env; self.beforeQueue = [];