diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index cf2a8adc..e1e7615a 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2100,6 +2100,12 @@ getJasmineRequireObj().Env = function(j$) { throw new Error(message); } }; + + this.cleanup_ = function() { + if (globalErrors) { + globalErrors.uninstall(); + } + }; } return Env; diff --git a/spec/core/EnvSpec.js b/spec/core/EnvSpec.js index aa87a997..61b962b1 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -5,6 +5,10 @@ describe('Env', function() { env = new jasmineUnderTest.Env(); }); + afterEach(function() { + env.cleanup_(); + }); + describe('#pending', function() { it('throws the Pending Spec exception', function() { expect(function() { @@ -281,11 +285,13 @@ describe('Env', function() { it('installs a global error handler on construction', function() { var globalErrors = jasmine.createSpyObj('globalErrors', [ 'install', + 'uninstall', 'pushListener', 'popListener' ]); spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors); - new jasmineUnderTest.Env(); + env.cleanup_(); + env = new jasmineUnderTest.Env(); expect(globalErrors.install).toHaveBeenCalled(); }); }); @@ -294,10 +300,12 @@ describe('Env', function() { it('does not install a global error handler until execute is called', function() { var globalErrors = jasmine.createSpyObj('globalErrors', [ 'install', + 'uninstall', 'pushListener', 'popListener' ]); spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors); + env.cleanup_(); env = new jasmineUnderTest.Env({ suppressLoadErrors: true }); expect(globalErrors.install).not.toHaveBeenCalled(); env.execute(); diff --git a/spec/core/ExceptionsSpec.js b/spec/core/ExceptionsSpec.js index 538c682d..c5e65754 100644 --- a/spec/core/ExceptionsSpec.js +++ b/spec/core/ExceptionsSpec.js @@ -5,6 +5,10 @@ describe('Exceptions:', function() { env = new jasmineUnderTest.Env(); }); + afterEach(function() { + env.cleanup_(); + }); + it('should handle exceptions thrown, but continue', function(done) { var secondTest = jasmine.createSpy('second test'); env.describe('Suite for handles exceptions', function() { diff --git a/spec/core/PrettyPrintSpec.js b/spec/core/PrettyPrintSpec.js index 1249d8c6..5c397eb5 100644 --- a/spec/core/PrettyPrintSpec.js +++ b/spec/core/PrettyPrintSpec.js @@ -327,52 +327,62 @@ describe('jasmineUnderTest.pp', function() { expect(jasmineUnderTest.pp(now)).toEqual('Date(' + now.toString() + ')'); }); - it('should stringify spy objects properly', function() { - var TestObject = { - someFunction: function() {} - }, - env = new jasmineUnderTest.Env(); + describe('with a spy object', function() { + var env; - var spyRegistry = new jasmineUnderTest.SpyRegistry({ - currentSpies: function() { - return []; - }, - createSpy: function(name, originalFn) { - return jasmineUnderTest.Spy(name, originalFn); - } + beforeEach(function() { + env = new jasmineUnderTest.Env(); }); - spyRegistry.spyOn(TestObject, 'someFunction'); - expect(jasmineUnderTest.pp(TestObject.someFunction)).toEqual( - 'spy on someFunction' - ); - - expect(jasmineUnderTest.pp(env.createSpy('something'))).toEqual( - 'spy on something' - ); - }); - - it('should stringify spyOn toString properly', function() { - var TestObject = { - someFunction: function() {} - }, - env = new jasmineUnderTest.Env(); - - var spyRegistry = new jasmineUnderTest.SpyRegistry({ - currentSpies: function() { - return []; - }, - createSpy: function(name, originalFn) { - return jasmineUnderTest.Spy(name, originalFn); - } + afterEach(function() { + env.cleanup_(); }); - spyRegistry.spyOn(TestObject, 'toString'); - var testSpyObj = env.createSpyObj('TheClassName', ['toString']); + it('should stringify spy objects properly', function() { + var TestObject = { + someFunction: function() {} + }; - expect(jasmineUnderTest.pp(testSpyObj)).toEqual( - 'spy on TheClassName.toString' - ); + var spyRegistry = new jasmineUnderTest.SpyRegistry({ + currentSpies: function() { + return []; + }, + createSpy: function(name, originalFn) { + return jasmineUnderTest.Spy(name, originalFn); + } + }); + + spyRegistry.spyOn(TestObject, 'someFunction'); + expect(jasmineUnderTest.pp(TestObject.someFunction)).toEqual( + 'spy on someFunction' + ); + + expect(jasmineUnderTest.pp(env.createSpy('something'))).toEqual( + 'spy on something' + ); + }); + + it('should stringify spyOn toString properly', function() { + var TestObject = { + someFunction: function() {} + }; + + var spyRegistry = new jasmineUnderTest.SpyRegistry({ + currentSpies: function() { + return []; + }, + createSpy: function(name, originalFn) { + return jasmineUnderTest.Spy(name, originalFn); + } + }); + + spyRegistry.spyOn(TestObject, 'toString'); + var testSpyObj = env.createSpyObj('TheClassName', ['toString']); + + expect(jasmineUnderTest.pp(testSpyObj)).toEqual( + 'spy on TheClassName.toString' + ); + }); }); it('should stringify objects that implement jasmineToString', function() { diff --git a/spec/core/SpySpec.js b/spec/core/SpySpec.js index b1165dd3..97d9f03b 100644 --- a/spec/core/SpySpec.js +++ b/spec/core/SpySpec.js @@ -5,6 +5,10 @@ describe('Spies', function() { env = new jasmineUnderTest.Env(); }); + afterEach(function() { + env.cleanup_(); + }); + describe('createSpy', function() { var TestClass; diff --git a/spec/core/SuiteSpec.js b/spec/core/SuiteSpec.js index 8470bad7..2a1cd757 100644 --- a/spec/core/SuiteSpec.js +++ b/spec/core/SuiteSpec.js @@ -1,28 +1,35 @@ describe('Suite', function() { + var env; + + beforeEach(function() { + env = new jasmineUnderTest.Env(); + }); + + afterEach(function() { + env.cleanup_(); + }); + it('keeps its id', function() { - var env = new jasmineUnderTest.Env(), - suite = new jasmineUnderTest.Suite({ - env: env, - id: 456, - description: 'I am a suite' - }); + var suite = new jasmineUnderTest.Suite({ + env: env, + id: 456, + description: 'I am a suite' + }); expect(suite.id).toEqual(456); }); it('returns blank full name for top level suite', function() { - var env = new jasmineUnderTest.Env(), - suite = new jasmineUnderTest.Suite({ - env: env, - description: 'I am a suite' - }); + var suite = new jasmineUnderTest.Suite({ + env: env, + description: 'I am a suite' + }); expect(suite.getFullName()).toEqual(''); }); it('returns its full name when it has parent suites', function() { - var env = new jasmineUnderTest.Env(), - parentSuite = new jasmineUnderTest.Suite({ + var parentSuite = new jasmineUnderTest.Suite({ env: env, description: 'I am a parent suite', parentSuite: jasmine.createSpy('pretend top level suite') @@ -37,8 +44,7 @@ describe('Suite', function() { }); it('adds before functions in order of needed execution', function() { - var env = new jasmineUnderTest.Env(), - suite = new jasmineUnderTest.Suite({ + var suite = new jasmineUnderTest.Suite({ env: env, description: 'I am a suite' }), @@ -52,8 +58,7 @@ describe('Suite', function() { }); it('adds after functions in order of needed execution', function() { - var env = new jasmineUnderTest.Env(), - suite = new jasmineUnderTest.Suite({ + var suite = new jasmineUnderTest.Suite({ env: env, description: 'I am a suite' }), @@ -115,13 +120,12 @@ describe('Suite', function() { }); it('calls timer to compute duration', function() { - var env = new jasmineUnderTest.Env(), - suite = new jasmineUnderTest.Suite({ - env: env, - id: 456, - description: 'I am a suite', - timer: jasmine.createSpyObj('timer', { start: null, elapsed: 77000 }) - }); + var suite = new jasmineUnderTest.Suite({ + env: env, + id: 456, + description: 'I am a suite', + timer: jasmine.createSpyObj('timer', { start: null, elapsed: 77000 }) + }); suite.startTimer(); suite.endTimer(); expect(suite.getResult().duration).toEqual(77000); diff --git a/spec/core/integration/CustomAsyncMatchersSpec.js b/spec/core/integration/CustomAsyncMatchersSpec.js index 0849e42a..a38ad472 100644 --- a/spec/core/integration/CustomAsyncMatchersSpec.js +++ b/spec/core/integration/CustomAsyncMatchersSpec.js @@ -6,6 +6,10 @@ describe('Custom Async Matchers (Integration)', function() { env.configure({random: false}); }); + afterEach(function() { + env.cleanup_(); + }); + it('passes the spec if the custom async matcher passes', function(done) { jasmine.getEnv().requirePromises(); diff --git a/spec/core/integration/CustomMatchersSpec.js b/spec/core/integration/CustomMatchersSpec.js index 17e66354..184c89be 100644 --- a/spec/core/integration/CustomMatchersSpec.js +++ b/spec/core/integration/CustomMatchersSpec.js @@ -7,6 +7,10 @@ describe("Custom Matchers (Integration)", function() { env.configure({random: false}); }); + afterEach(function() { + env.cleanup_(); + }); + it("allows adding more matchers local to a spec", function(done) { env.it('spec defining a custom matcher', function() { env.addMatchers({ diff --git a/spec/core/integration/CustomSpyStrategiesSpec.js b/spec/core/integration/CustomSpyStrategiesSpec.js index 796d3478..7ab4d28d 100644 --- a/spec/core/integration/CustomSpyStrategiesSpec.js +++ b/spec/core/integration/CustomSpyStrategiesSpec.js @@ -6,6 +6,10 @@ describe('Custom Spy Strategies (Integration)', function() { env.configure({random: false}); }); + afterEach(function() { + env.cleanup_(); + }); + it('allows adding more strategies local to a suite', function(done) { var plan = jasmine.createSpy('custom strategy plan') .and.returnValue(42); diff --git a/spec/core/integration/DefaultSpyStrategySpec.js b/spec/core/integration/DefaultSpyStrategySpec.js index 0b02c572..584b25b2 100644 --- a/spec/core/integration/DefaultSpyStrategySpec.js +++ b/spec/core/integration/DefaultSpyStrategySpec.js @@ -6,6 +6,10 @@ describe('Default Spy Strategy (Integration)', function() { env.configure({random: false}); }); + afterEach(function() { + env.cleanup_(); + }); + it('allows defining a default spy strategy', function(done) { env.describe('suite with default strategy', function() { env.beforeEach(function() { diff --git a/spec/core/integration/EnvSpec.js b/spec/core/integration/EnvSpec.js index eef02e6c..490e9d94 100644 --- a/spec/core/integration/EnvSpec.js +++ b/spec/core/integration/EnvSpec.js @@ -1,11 +1,17 @@ describe("Env integration", function() { + var env; + beforeEach(function() { jasmine.getEnv().registerIntegrationMatchers(); + env = new jasmineUnderTest.Env(); + }); + + afterEach(function() { + env.cleanup_(); }); it("Suites execute as expected (no nesting)", function(done) { - var env = new jasmineUnderTest.Env(), - calls = []; + var calls = []; var assertions = function() { expect(calls).toEqual([ @@ -32,8 +38,7 @@ describe("Env integration", function() { }); it("Nested Suites execute as expected", function(done) { - var env = new jasmineUnderTest.Env(), - calls = []; + var calls = []; var assertions = function() { expect(calls).toEqual([ @@ -66,8 +71,7 @@ describe("Env integration", function() { }); it("Multiple top-level Suites execute as expected", function(done) { - var env = new jasmineUnderTest.Env(), - calls = []; + var calls = []; var assertions = function() { expect(calls).toEqual([ @@ -108,8 +112,7 @@ describe("Env integration", function() { }); it('explicitly fails a spec', function(done) { - var env = new jasmineUnderTest.Env(), - specDone = jasmine.createSpy('specDone'); + var specDone = jasmine.createSpy('specDone'); env.addReporter({ specDone: specDone, @@ -179,8 +182,7 @@ describe("Env integration", function() { }); it("produces an understandable error message when 'fail' is used outside of a current spec", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']); + var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']); reporter.jasmineDone.and.callFake(done); env.addReporter(reporter); @@ -197,8 +199,6 @@ describe("Env integration", function() { it("calls associated befores/specs/afters with the same 'this'", function(done) { - var env = new jasmineUnderTest.Env(); - env.addReporter({jasmineDone: done}); env.configure({random: false}); env.describe("tests", function() { @@ -235,8 +235,6 @@ describe("Env integration", function() { }); it("calls associated befores/its/afters with the same 'this' for an async spec", function(done) { - var env = new jasmineUnderTest.Env(); - env.addReporter({jasmineDone: done}); env.describe("with an async spec", function() { @@ -261,8 +259,7 @@ describe("Env integration", function() { }); it("calls associated beforeAlls/afterAlls only once per suite", function(done) { - var env = new jasmineUnderTest.Env(), - before = jasmine.createSpy('beforeAll'), + var before = jasmine.createSpy('beforeAll'), after = jasmine.createSpy('afterAll'); env.addReporter({ @@ -293,8 +290,7 @@ describe("Env integration", function() { }); it("calls associated beforeAlls/afterAlls only once per suite for async", function(done) { - var env = new jasmineUnderTest.Env(), - before = jasmine.createSpy('beforeAll'), + var before = jasmine.createSpy('beforeAll'), after = jasmine.createSpy('afterAll'); env.addReporter({ @@ -332,8 +328,6 @@ describe("Env integration", function() { }); it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) { - var env = new jasmineUnderTest.Env(); - env.addReporter({jasmineDone: done}); env.describe("with beforeAll and afterAll", function() { @@ -386,8 +380,6 @@ describe("Env integration", function() { }); it("tags top-level afterAll failures with a type", function(done) { - var env = new jasmineUnderTest.Env(); - env.addReporter({jasmineDone: function(result) { expect(result.failedExpectations[0].globalErrorType).toEqual('afterAll'); done(); @@ -403,8 +395,7 @@ describe("Env integration", function() { }); it("does not tag suite afterAll failures with a type", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = { + var reporter = { jasmineDone: function() { expect(reporter.suiteDone).toHaveBeenCalled(); done(); @@ -428,8 +419,7 @@ describe("Env integration", function() { }); it("when the beforeAll fails, error at suite level", function (done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "suiteDone", "jasmineDone" ]); + var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "suiteDone", "jasmineDone" ]); reporter.jasmineDone.and.callFake(function() { expect(reporter.specDone.calls.count()).toEqual(2); @@ -465,8 +455,9 @@ describe("Env integration", function() { clearTimeout: function(fn, delay) { clearTimeout(fn, delay) }, }; spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone", "suiteDone" ]); + env.cleanup_(); + env = new jasmineUnderTest.Env(); + var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone", "suiteDone" ]); reporter.jasmineDone.and.callFake(function() { expect(reporter.specDone).not.toHaveFailedExpectationsForRunnable('A suite fails', ['fail thrown']); @@ -498,8 +489,7 @@ describe("Env integration", function() { describe('suiteDone reporting', function(){ it("reports when an afterAll fails an expectation", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); + var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); reporter.jasmineDone.and.callFake(function() { expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [ @@ -525,8 +515,7 @@ describe("Env integration", function() { }); it("if there are no specs, it still reports correctly", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); + var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); reporter.jasmineDone.and.callFake(function() { expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer suite', [ @@ -553,8 +542,7 @@ describe("Env integration", function() { }); it("reports when afterAll throws an exception", function(done) { - var env = new jasmineUnderTest.Env(), - error = new Error('After All Exception'), + var error = new Error('After All Exception'), reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); reporter.jasmineDone.and.callFake(function() { @@ -579,8 +567,7 @@ describe("Env integration", function() { }); it("reports when an async afterAll fails an expectation", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); + var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); reporter.jasmineDone.and.callFake(function() { expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [ @@ -605,8 +592,7 @@ describe("Env integration", function() { }); it("reports when an async afterAll throws an exception", function(done) { - var env = new jasmineUnderTest.Env(), - error = new Error('After All Exception'), + var error = new Error('After All Exception'), reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); @@ -633,8 +619,7 @@ describe("Env integration", function() { }); it('reports expectation failures in global beforeAll', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']); + var reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']); reporter.jasmineDone.and.callFake(function(results) { expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]); @@ -656,8 +641,7 @@ describe("Env integration", function() { }); it('reports expectation failures in global afterAll', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj(['jasmineDone']); + var reporter = jasmine.createSpyObj(['jasmineDone']); reporter.jasmineDone.and.callFake(function(results) { expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]); @@ -678,8 +662,7 @@ describe("Env integration", function() { }); it("Allows specifying which specs and suites to run", function(done) { - var env = new jasmineUnderTest.Env(), - calls = [], + var calls = [], suiteCallback = jasmine.createSpy('suite callback'), firstSpec, secondSuite; @@ -714,8 +697,7 @@ describe("Env integration", function() { }); it('runs before and after all functions for runnables provided to .execute()', function(done) { - var env = new jasmineUnderTest.Env(), - calls = [], + var calls = [], first_spec, second_spec; @@ -750,8 +732,7 @@ describe("Env integration", function() { }); it("Allows filtering out specs and suites to run programmatically", function(done) { - var env = new jasmineUnderTest.Env(), - calls = [], + var calls = [], suiteCallback = jasmine.createSpy('suite callback'), firstSpec, secondSuite; @@ -793,8 +774,6 @@ describe("Env integration", function() { }); it("Functions can be spied on and have their calls tracked", function (done) { - var env = new jasmineUnderTest.Env(); - var originalFunctionWasCalled = false; var subject = { spiedFunc: function() { @@ -833,8 +812,7 @@ describe("Env integration", function() { }); it('can be configured to allow respying on functions', function (done) { - var env = new jasmineUnderTest.Env(), - foo = { + var foo = { bar: function () { return 1; } @@ -859,8 +837,7 @@ describe("Env integration", function() { }); it('removes all spies added in a spec after the spec is complete', function(done) { - var env = new jasmineUnderTest.Env(), - originalFoo = function() {}, + var originalFoo = function() {}, testObj = { foo: originalFoo }, @@ -887,8 +864,7 @@ describe("Env integration", function() { }); it('removes all spies added in a suite after the suite is complete', function(done) { - var env = new jasmineUnderTest.Env(), - originalFoo = function() {}, + var originalFoo = function() {}, testObj = { foo: originalFoo }; @@ -917,8 +893,7 @@ describe("Env integration", function() { }); it('removes a spy from the top suite after the run is complete', function(done) { - var env = new jasmineUnderTest.Env(), - originalFoo = function() {}, + var originalFoo = function() {}, testObj = { foo: originalFoo }; @@ -944,8 +919,10 @@ describe("Env integration", function() { it("Mock clock can be installed and used in tests", function(done) { var globalSetTimeout = jasmine.createSpy('globalSetTimeout').and.callFake(function(cb, t) { setTimeout(cb, t); }), delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'), - delayedFunctionForMockClock = jasmine.createSpy('delayedFunctionForMockClock'), - env = new jasmineUnderTest.Env({global: { setTimeout: globalSetTimeout, clearTimeout: clearTimeout, setImmediate: function(cb) { setTimeout(cb, 0); } }}); + delayedFunctionForMockClock = jasmine.createSpy('delayedFunctionForMockClock'); + + env.cleanup_(); + env = new jasmineUnderTest.Env({global: { setTimeout: globalSetTimeout, clearTimeout: clearTimeout, setImmediate: function(cb) { setTimeout(cb, 0); } }}); var assertions = function() { expect(delayedFunctionForMockClock).toHaveBeenCalled(); @@ -976,8 +953,7 @@ describe("Env integration", function() { }); it("should run async specs in order, waiting for them to complete", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone']), + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone']), mutatedVar; reporter.jasmineDone.and.callFake(function() { @@ -1008,9 +984,10 @@ describe("Env integration", function() { describe("with a mock clock", function() { var realSetTimeout; function createMockedEnv() { + env.cleanup_(); // explicitly pass in timing functions so we can make sure that clear stack always works // no matter how long the suite in the spec is - return new jasmineUnderTest.Env({ global: { + env = new jasmineUnderTest.Env({ global: { setTimeout: function(cb, t) { var stack = jasmine.util.errorWithStack().stack; if (stack.indexOf('ClearStack') >= 0) { @@ -1040,8 +1017,8 @@ describe("Env integration", function() { }); it("should wait a default interval before failing specs that haven't called done yet", function(done) { - var env = createMockedEnv(), - reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]); + createMockedEnv(); + var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]); reporter.specDone.and.callFake(function(result) { expect(result).toEqual(jasmine.objectContaining({status: 'failed'})); @@ -1069,8 +1046,8 @@ describe("Env integration", function() { }); it("should not use the mock clock for asynchronous timeouts", function(done){ - var env = createMockedEnv(), - reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]), + createMockedEnv(); + var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]), clock = env.clock; reporter.specDone.and.callFake(function() { @@ -1107,8 +1084,8 @@ describe("Env integration", function() { }); it('should wait a custom interval before reporting async functions that fail to complete', function(done) { - var env = createMockedEnv(), - reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']); + createMockedEnv(); + var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(r) { expect(r.failedExpectations).toEqual([]); @@ -1207,8 +1184,7 @@ describe("Env integration", function() { }); it('explicitly fails an async spec', function(done) { - var env = new jasmineUnderTest.Env(), - specDone = jasmine.createSpy('specDone'); + var specDone = jasmine.createSpy('specDone'); env.addReporter({ specDone: specDone, @@ -1273,8 +1249,7 @@ describe("Env integration", function() { describe('focused tests', function() { it('should only run the focused tests', function(done) { - var env = new jasmineUnderTest.Env(), - calls = []; + var calls = []; var assertions = function() { expect(calls).toEqual(['focused']); @@ -1297,8 +1272,7 @@ describe("Env integration", function() { }); it('should only run focused suites', function(done){ - var env = new jasmineUnderTest.Env(), - calls = []; + var calls = []; var assertions = function() { expect(calls).toEqual(['focused']); @@ -1323,8 +1297,7 @@ describe("Env integration", function() { }); it('should run focused tests inside an xdescribe', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineStarted", "jasmineDone", "suiteStarted", @@ -1359,8 +1332,7 @@ describe("Env integration", function() { }); it('should run focused suites inside an xdescribe', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineStarted", "jasmineDone", "suiteStarted", @@ -1398,8 +1370,7 @@ describe("Env integration", function() { }); it("should report as expected", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineStarted", "jasmineDone", "suiteStarted", @@ -1472,8 +1443,7 @@ describe("Env integration", function() { }); it("should report the random seed at the beginning and end of execution", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineStarted", "jasmineDone", "suiteStarted", @@ -1500,8 +1470,7 @@ describe("Env integration", function() { }); it('should report pending spec messages', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ 'specDone', 'jasmineDone' ]); @@ -1537,8 +1506,7 @@ describe("Env integration", function() { reject(this.exception); }; - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ 'specDone', 'jasmineDone' ]); @@ -1564,8 +1532,7 @@ describe("Env integration", function() { }); it('should report using fallback reporter', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ 'specDone', 'jasmineDone' ]); @@ -1586,8 +1553,7 @@ describe("Env integration", function() { }); it('should report xdescribes as expected', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineStarted", "jasmineDone", "suiteStarted", @@ -1627,8 +1593,7 @@ describe("Env integration", function() { }); it("should be possible to get full name from a spec", function() { - var env = new jasmineUnderTest.Env(), - topLevelSpec, nestedSpec, doublyNestedSpec; + var topLevelSpec, nestedSpec, doublyNestedSpec; env.describe("my tests", function() { topLevelSpec = env.it("are sometimes top level", function() { @@ -1649,8 +1614,7 @@ describe("Env integration", function() { }); it("Custom equality testers should be per spec", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineDone", "specDone" ]); @@ -1683,8 +1647,7 @@ describe("Env integration", function() { }); it("Custom equality testers should be per suite", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineDone", "specDone" ]); @@ -1726,8 +1689,7 @@ describe("Env integration", function() { }); it("Custom equality testers for toContain should be per spec", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineDone", "specDone" ]); @@ -1760,8 +1722,7 @@ describe("Env integration", function() { }); it("produces an understandable error message when an 'expect' is used outside of a current spec", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']); + var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']); reporter.jasmineDone.and.callFake(done); env.addReporter(reporter); @@ -1777,8 +1738,7 @@ describe("Env integration", function() { }); it("Custom equality testers for toContain should be per suite", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReporter', [ + var reporter = jasmine.createSpyObj('fakeReporter', [ "jasmineDone", "specDone" ]); @@ -1820,8 +1780,7 @@ describe("Env integration", function() { }); it("Custom matchers should be per spec", function(done) { - var env = new jasmineUnderTest.Env(), - matchers = { + var matchers = { toFoo: function() {} }; @@ -1842,8 +1801,7 @@ describe("Env integration", function() { }); it("Custom matchers should be per suite", function(done) { - var env = new jasmineUnderTest.Env(), - matchers = { + var matchers = { toFoo: function() {} }; @@ -1871,8 +1829,7 @@ describe("Env integration", function() { }); it('throws an exception if you try to create a spy outside of a runnable', function (done) { - var env = new jasmineUnderTest.Env(), - obj = {fn: function () {}}, + var obj = {fn: function () {}}, exception; env.describe("a suite", function () { @@ -1894,8 +1851,7 @@ describe("Env integration", function() { }); it('throws an exception if you try to add a matcher outside of a runnable', function (done) { - var env = new jasmineUnderTest.Env(), - obj = {fn: function () {}}, + var obj = {fn: function () {}}, exception; env.describe("a suite", function () { @@ -1917,8 +1873,7 @@ describe("Env integration", function() { }); it('throws an exception if you try to add a custom equality outside of a runnable', function (done) { - var env = new jasmineUnderTest.Env(), - obj = {fn: function () {}}, + var obj = {fn: function () {}}, exception; env.describe("a suite", function () { @@ -1940,8 +1895,7 @@ describe("Env integration", function() { }); it("should associate errors thrown from async code with the correct runnable", function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone','specDone']); + var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone','specDone']); reporter.jasmineDone.and.callFake(function() { expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('async suite', [ @@ -1973,8 +1927,7 @@ describe("Env integration", function() { }); it('should throw on suites/specs/befores/afters nested in methods other than \'describe\'', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function() { var msg = /\'.*\' should only be used in \'describe\' function/; @@ -2037,11 +1990,13 @@ describe("Env integration", function() { var global = { setTimeout: function(fn, delay) { setTimeout(fn, delay) }, clearTimeout: function(fn, delay) { clearTimeout(fn, delay) }, + onerror: function() {} }; spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + env.cleanup_(); + env = new jasmineUnderTest.Env(); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.failedExpectations).toEqual([ @@ -2087,8 +2042,9 @@ describe("Env integration", function() { globalErrors.pushListener(onerror); spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors); - var env = new jasmineUnderTest.Env({suppressLoadErrors: true}); - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + env.cleanup_(); + env = new jasmineUnderTest.Env({suppressLoadErrors: true}); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.failedExpectations).toEqual([]); @@ -2106,8 +2062,7 @@ describe("Env integration", function() { describe('Overall status in the jasmineDone event', function() { describe('When everything passes', function() { it('is "passed"', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('passed'); @@ -2122,8 +2077,7 @@ describe("Env integration", function() { describe('When a spec fails', function() { it('is "failed"', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('failed'); @@ -2139,10 +2093,9 @@ describe("Env integration", function() { }); describe('when spec has no expectations', function() { - var env, reporter; + var reporter; beforeEach(function() { - env = new jasmineUnderTest.Env(); reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); env.addReporter(reporter); @@ -2175,8 +2128,7 @@ describe("Env integration", function() { describe('When a top-level beforeAll fails', function() { it('is "failed"', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('failed'); @@ -2194,8 +2146,7 @@ describe("Env integration", function() { describe('When a suite beforeAll fails', function() { it('is "failed"', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('failed'); @@ -2215,8 +2166,7 @@ describe("Env integration", function() { describe('When a top-level afterAll fails', function() { it('is "failed"', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('failed'); @@ -2234,8 +2184,7 @@ describe("Env integration", function() { describe('When a suite afterAll fails', function() { it('is "failed"', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('failed'); @@ -2261,7 +2210,8 @@ describe("Env integration", function() { }; spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); - var env = new jasmineUnderTest.Env(); + env.cleanup_(); + env = new jasmineUnderTest.Env(); var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { @@ -2278,8 +2228,7 @@ describe("Env integration", function() { describe('When there are no specs', function() { it('is "incomplete"', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('incomplete'); @@ -2294,8 +2243,7 @@ describe("Env integration", function() { describe('When a spec is focused', function() { it('is "incomplete"', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('incomplete'); @@ -2311,8 +2259,7 @@ describe("Env integration", function() { describe('When a suite is focused', function() { it('is "incomplete"', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('incomplete'); @@ -2330,8 +2277,7 @@ describe("Env integration", function() { describe('When there are both failures and focused specs', function() { it('is "failed"', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter.jasmineDone.and.callFake(function(e) { expect(e.overallStatus).toEqual('failed'); @@ -2349,8 +2295,7 @@ describe("Env integration", function() { }); it('should report deprecation warnings on the correct specs and suites', function(done) { - var env = new jasmineUnderTest.Env(), - reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); + var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); // prevent deprecation from being displayed spyOn(console, "error"); @@ -2395,8 +2340,7 @@ describe("Env integration", function() { }); it('should report deprecation stack with an error object', function(done) { - var env = new jasmineUnderTest.Env(), - exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(), + var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(), reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']), topLevelError, suiteLevelError, specLevelError; @@ -2458,8 +2402,7 @@ describe("Env integration", function() { it('supports async matchers', function(done) { jasmine.getEnv().requirePromises(); - var env = new jasmineUnderTest.Env(), - specDone = jasmine.createSpy('specDone'), + var specDone = jasmine.createSpy('specDone'), suiteDone = jasmine.createSpy('suiteDone'); env.addReporter({ @@ -2507,8 +2450,7 @@ describe("Env integration", function() { it('provides custom equality testers to async matchers', function(done) { jasmine.getEnv().requirePromises(); - var env = new jasmineUnderTest.Env(), - specDone = jasmine.createSpy('specDone'); + var specDone = jasmine.createSpy('specDone'); env.addReporter({ specDone: specDone, @@ -2533,8 +2475,7 @@ describe("Env integration", function() { it('includes useful stack frames in async matcher failures', function(done) { jasmine.getEnv().requirePromises(); - var env = new jasmineUnderTest.Env(), - specDone = jasmine.createSpy('specDone'); + var specDone = jasmine.createSpy('specDone'); env.addReporter({ specDone: specDone, @@ -2560,8 +2501,7 @@ describe("Env integration", function() { it('reports an error when an async expectation occurs after the spec finishes', function(done) { jasmine.getEnv().requirePromises(); - var env = new jasmineUnderTest.Env(), - resolve, + var resolve, promise = new Promise(function(res) { resolve = res; }); env.describe('a suite', function() { @@ -2609,8 +2549,7 @@ describe("Env integration", function() { it('reports an error when an async expectation occurs after the suite finishes', function(done) { jasmine.getEnv().requirePromises(); - var env = new jasmineUnderTest.Env(), - resolve, + var resolve, promise = new Promise(function(res) { resolve = res; }); env.describe('a suite', function() { diff --git a/spec/core/integration/MatchersSpec.js b/spec/core/integration/MatchersSpec.js index f75aae28..95eaf041 100644 --- a/spec/core/integration/MatchersSpec.js +++ b/spec/core/integration/MatchersSpec.js @@ -1,7 +1,16 @@ describe('Matchers (Integration)', function() { + var env; + + beforeEach(function() { + env = new jasmineUnderTest.Env(); + }); + + afterEach(function() { + env.cleanup_(); + }); + function verifyPasses(expectations) { it('passes', function(done) { - var env = new jasmineUnderTest.Env(); env.it('a spec', function() { expectations(env); }); @@ -26,7 +35,6 @@ describe('Matchers (Integration)', function() { function verifyFails(expectations) { it('fails', function(done) { - var env = new jasmineUnderTest.Env(); env.it('a spec', function() { expectations(env); }); @@ -51,7 +59,6 @@ describe('Matchers (Integration)', function() { function verifyPassesAsync(expectations) { it('passes', function(done) { jasmine.getEnv().requirePromises(); - var env = new jasmineUnderTest.Env(); env.it('a spec', function() { return expectations(env); @@ -77,7 +84,6 @@ describe('Matchers (Integration)', function() { function verifyFailsAsync(expectations) { it('fails', function(done) { - var env = new jasmineUnderTest.Env(); jasmine.getEnv().requirePromises(); env.it('a spec', function() { diff --git a/spec/core/integration/SpecRunningSpec.js b/spec/core/integration/SpecRunningSpec.js index 1bd670b4..d522cf86 100644 --- a/spec/core/integration/SpecRunningSpec.js +++ b/spec/core/integration/SpecRunningSpec.js @@ -7,6 +7,10 @@ describe("spec running", function () { env.configure({random: false}); }); + afterEach(function() { + env.cleanup_(); + }); + it('should assign spec ids sequentially', function() { var it0, it1, it2, it3, it4; env.describe('test suite', function() { diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index 508a5bfd..d5d88ab3 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -678,7 +678,6 @@ describe("matchersUtil", function() { }, diffBuilder = jasmine.createSpyObj('diffBuilder', ['record', 'withPath']); diffBuilder.withPath.and.callFake(function(p, block) { block() }); - debugger; jasmineUnderTest.matchersUtil.equals({x: 42}, {x: tester}, [], diffBuilder); expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function)); @@ -693,7 +692,6 @@ describe("matchersUtil", function() { }, diffBuilder = jasmine.createSpyObj('diffBuilder', ['record', 'withPath']); diffBuilder.withPath.and.callFake(function(p, block) { block() }); - debugger; jasmineUnderTest.matchersUtil.equals({x: 42}, {x: tester}, [], diffBuilder); expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function)); diff --git a/spec/core/matchers/toHaveBeenCalledBeforeSpec.js b/spec/core/matchers/toHaveBeenCalledBeforeSpec.js index f2e89c2f..53aa3fdb 100644 --- a/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +++ b/spec/core/matchers/toHaveBeenCalledBeforeSpec.js @@ -1,24 +1,30 @@ -describe("toHaveBeenCalledBefore", function() { - it("throws an exception when the actual is not a spy", function() { +describe("toHaveBeenCalledBefore", function () { + it("throws an exception when the actual is not a spy", function () { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(), - fn = function() {}, - secondSpy = new jasmineUnderTest.Env().createSpy('second spy'); + fn = function () { + }, + spy = new jasmineUnderTest.Spy('a spy'); - expect(function() { matcher.compare(fn, secondSpy) }).toThrowError(Error, /Expected a spy, but got Function./); + expect(function () { + matcher.compare(fn, spy) + }).toThrowError(Error, /Expected a spy, but got Function./); }); - it("throws an exception when the expected is not a spy", function() { + it("throws an exception when the expected is not a spy", function () { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(), - firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), - fn = function() {}; + spy = new jasmineUnderTest.Spy('a spy'), + fn = function () { + }; - expect(function() { matcher.compare(firstSpy, fn) }).toThrowError(Error, /Expected a spy, but got Function./); + expect(function () { + matcher.compare(spy, fn) + }).toThrowError(Error, /Expected a spy, but got Function./); }); - it("fails when the actual was not called", function() { + it("fails when the actual was not called", function () { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(), - firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), - secondSpy = new jasmineUnderTest.Env().createSpy('second spy'); + firstSpy = new jasmineUnderTest.Spy('first spy'), + secondSpy = new jasmineUnderTest.Spy('second spy'); secondSpy(); @@ -27,10 +33,10 @@ describe("toHaveBeenCalledBefore", function() { expect(result.message).toMatch(/Expected spy first spy to have been called./); }); - it("fails when the expected was not called", function() { + it("fails when the expected was not called", function () { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(), - firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), - secondSpy = new jasmineUnderTest.Env().createSpy('second spy'); + firstSpy = new jasmineUnderTest.Spy('first spy'), + secondSpy = new jasmineUnderTest.Spy('second spy'); firstSpy(); @@ -39,11 +45,11 @@ describe("toHaveBeenCalledBefore", function() { expect(result.message).toMatch(/Expected spy second spy to have been called./); }); - it("fails when the actual is called after the expected", function() { + it("fails when the actual is called after the expected", function () { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(), - firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), - secondSpy = new jasmineUnderTest.Env().createSpy('second spy'), - result; + firstSpy = new jasmineUnderTest.Spy('first spy'), + secondSpy = new jasmineUnderTest.Spy('second spy'), + result; secondSpy(); firstSpy(); @@ -53,11 +59,11 @@ describe("toHaveBeenCalledBefore", function() { expect(result.message).toEqual('Expected spy first spy to have been called before spy second spy'); }); - it("fails when the actual is called before and after the expected", function() { + it("fails when the actual is called before and after the expected", function () { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(), - firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), - secondSpy = new jasmineUnderTest.Env().createSpy('second spy'), - result; + firstSpy = new jasmineUnderTest.Spy('first spy'), + secondSpy = new jasmineUnderTest.Spy('second spy'), + result; firstSpy(); secondSpy(); @@ -68,11 +74,11 @@ describe("toHaveBeenCalledBefore", function() { expect(result.message).toEqual('Expected latest call to spy first spy to have been called before first call to spy second spy (no interleaved calls)'); }); - it("fails when the expected is called before and after the actual", function() { + it("fails when the expected is called before and after the actual", function () { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(), - firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), - secondSpy = new jasmineUnderTest.Env().createSpy('second spy'), - result; + firstSpy = new jasmineUnderTest.Spy('first spy'), + secondSpy = new jasmineUnderTest.Spy('second spy'), + result; secondSpy(); firstSpy(); @@ -83,11 +89,11 @@ describe("toHaveBeenCalledBefore", function() { expect(result.message).toEqual('Expected first call to spy second spy to have been called after latest call to spy first spy (no interleaved calls)'); }); - it("passes when the actual is called before the expected", function() { + it("passes when the actual is called before the expected", function () { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(), - firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), - secondSpy = new jasmineUnderTest.Env().createSpy('second spy'), - result; + firstSpy = new jasmineUnderTest.Spy('first spy'), + secondSpy = new jasmineUnderTest.Spy('second spy'), + result; firstSpy(); secondSpy(); diff --git a/spec/core/matchers/toHaveBeenCalledSpec.js b/spec/core/matchers/toHaveBeenCalledSpec.js index b14116f0..d39236c0 100644 --- a/spec/core/matchers/toHaveBeenCalledSpec.js +++ b/spec/core/matchers/toHaveBeenCalledSpec.js @@ -1,7 +1,7 @@ describe("toHaveBeenCalled", function() { it("passes when the actual was called, with a custom .not fail message", function() { var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(), - calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'), + calledSpy = new jasmineUnderTest.Spy('called-spy'), result; calledSpy(); @@ -13,7 +13,7 @@ describe("toHaveBeenCalled", function() { it("fails when the actual was not called", function() { var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(), - uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'), + uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'), result; result = matcher.compare(uncalledSpy); @@ -29,14 +29,14 @@ describe("toHaveBeenCalled", function() { it("throws an exception when invoked with any arguments", function() { var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(), - spy = new jasmineUnderTest.Env().createSpy('sample spy'); + spy = new jasmineUnderTest.Spy('sample spy'); expect(function() { matcher.compare(spy, 'foo') }).toThrowError(Error, /Does not take arguments, use toHaveBeenCalledWith/); }); it("has a custom message on failure", function() { var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(), - spy = new jasmineUnderTest.Env().createSpy('sample-spy'), + spy = new jasmineUnderTest.Spy('sample-spy'), result; result = matcher.compare(spy); diff --git a/spec/core/matchers/toHaveBeenCalledTimesSpec.js b/spec/core/matchers/toHaveBeenCalledTimesSpec.js index 62778fbd..7b3ad2b5 100644 --- a/spec/core/matchers/toHaveBeenCalledTimesSpec.js +++ b/spec/core/matchers/toHaveBeenCalledTimesSpec.js @@ -1,14 +1,14 @@ describe("toHaveBeenCalledTimes", function() { it("passes when the actual 0 matches the expected 0 ", function () { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), - calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'), + calledSpy = new jasmineUnderTest.Spy('called-spy'), result; result = matcher.compare(calledSpy, 0); expect(result.pass).toBeTruthy(); }); it("passes when the actual matches the expected", function() { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), - calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'), + calledSpy = new jasmineUnderTest.Spy('called-spy'), result; calledSpy(); @@ -18,7 +18,7 @@ describe("toHaveBeenCalledTimes", function() { it("fails when expected numbers is not supplied", function(){ var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), - spy = new jasmineUnderTest.Env().createSpy('spy'), + spy = new jasmineUnderTest.Spy('spy'), result; spy(); @@ -29,7 +29,7 @@ describe("toHaveBeenCalledTimes", function() { it("fails when the actual was called less than the expected", function() { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), - uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'), + uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'), result; result = matcher.compare(uncalledSpy, 2); @@ -38,7 +38,7 @@ describe("toHaveBeenCalledTimes", function() { it("fails when the actual was called more than expected", function() { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), - uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'), + uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'), result; uncalledSpy(); @@ -59,7 +59,7 @@ describe("toHaveBeenCalledTimes", function() { it("has a custom message on failure that tells it was called only once", function() { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), - spy = new jasmineUnderTest.Env().createSpy('sample-spy'), + spy = new jasmineUnderTest.Spy('sample-spy'), result; spy(); spy(); @@ -72,7 +72,7 @@ describe("toHaveBeenCalledTimes", function() { it("has a custom message on failure that tells how many times it was called", function() { var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), - spy = new jasmineUnderTest.Env().createSpy('sample-spy'), + spy = new jasmineUnderTest.Spy('sample-spy'), result; spy(); spy(); diff --git a/spec/core/matchers/toHaveBeenCalledWithSpec.js b/spec/core/matchers/toHaveBeenCalledWithSpec.js index 4ac7e074..9cc3415b 100644 --- a/spec/core/matchers/toHaveBeenCalledWithSpec.js +++ b/spec/core/matchers/toHaveBeenCalledWithSpec.js @@ -5,7 +5,7 @@ describe("toHaveBeenCalledWith", function() { contains: jasmine.createSpy('delegated-contains').and.returnValue(true) }, matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util), - calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'), + calledSpy = new jasmineUnderTest.Spy('called-spy'), result; calledSpy('a', 'b'); @@ -21,7 +21,7 @@ describe("toHaveBeenCalledWith", function() { }, customEqualityTesters = [function() { return true; }], matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util, customEqualityTesters), - calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'); + calledSpy = new jasmineUnderTest.Spy('called-spy'); calledSpy('a', 'b'); matcher.compare(calledSpy, 'a', 'b'); @@ -34,7 +34,7 @@ describe("toHaveBeenCalledWith", function() { contains: jasmine.createSpy('delegated-contains').and.returnValue(false) }, matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util), - uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'), + uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'), result; result = matcher.compare(uncalledSpy); @@ -45,7 +45,7 @@ describe("toHaveBeenCalledWith", function() { it("fails when the actual was called with different parameters", function() { var util = jasmineUnderTest.matchersUtil, matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util), - calledSpy = new jasmineUnderTest.Env().createSpy('called spy'), + calledSpy = new jasmineUnderTest.Spy('called spy'), result; calledSpy('a'); diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index 526fa76c..3b4f20e5 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -1,7 +1,16 @@ describe('HtmlReporter', function() { + var env; + + beforeEach(function() { + env = new jasmineUnderTest.Env(); + }); + + afterEach(function() { + env.cleanup_(); + }); + it('builds the initial DOM elements, including the title banner', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -37,8 +46,7 @@ describe('HtmlReporter', function() { }); it('builds a single reporter even if initialized multiple times', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -71,7 +79,7 @@ describe('HtmlReporter', function() { container = document.createElement('div'); reporter = new jasmineUnderTest.HtmlReporter({ - env: new jasmineUnderTest.Env(), + env: env, getContainer: function() { return container; }, @@ -119,8 +127,7 @@ describe('HtmlReporter', function() { }); it('reports the status symbol of a excluded spec', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -152,8 +159,7 @@ describe('HtmlReporter', function() { }); it('reports the status symbol of a pending spec', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -182,8 +188,7 @@ describe('HtmlReporter', function() { }); it('reports the status symbol of a passing spec', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -213,8 +218,7 @@ describe('HtmlReporter', function() { }); it('reports the status symbol of a failing spec', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -246,8 +250,7 @@ describe('HtmlReporter', function() { describe('when there are deprecation warnings', function() { it('displays the messages in their own alert bars', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -298,8 +301,7 @@ describe('HtmlReporter', function() { if (!window.console) { window.console = { error: function() {} }; } - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -343,8 +345,7 @@ describe('HtmlReporter', function() { }); it('reports the run time', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -372,8 +373,7 @@ describe('HtmlReporter', function() { }); it('reports the suite and spec names with status', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -490,8 +490,7 @@ describe('HtmlReporter', function() { }); it('has an options menu', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -529,8 +528,7 @@ describe('HtmlReporter', function() { describe('when there are global errors', function() { it('displays the exceptions in their own alert bars', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -576,8 +574,7 @@ describe('HtmlReporter', function() { }); it('displays file and line information if available', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -619,8 +616,7 @@ describe('HtmlReporter', function() { describe('UI for stop on spec failure', function() { it('should be unchecked for full execution', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -643,8 +639,7 @@ describe('HtmlReporter', function() { }); it('should be checked if stopping short', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -669,8 +664,7 @@ describe('HtmlReporter', function() { }); it('should navigate and turn the setting on', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), navigationHandler = jasmine.createSpy('navigate'), getContainer = function() { return container; @@ -697,8 +691,7 @@ describe('HtmlReporter', function() { }); it('should navigate and turn the setting off', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), navigationHandler = jasmine.createSpy('navigate'), getContainer = function() { return container; @@ -729,8 +722,7 @@ describe('HtmlReporter', function() { describe('UI for throwing errors on expectation failures', function() { it('should be unchecked if not throwing', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -753,8 +745,7 @@ describe('HtmlReporter', function() { }); it('should be checked if throwing', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -779,8 +770,7 @@ describe('HtmlReporter', function() { }); it('should navigate and change the setting to on', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), navigateHandler = jasmine.createSpy('navigate'), getContainer = function() { return container; @@ -807,8 +797,7 @@ describe('HtmlReporter', function() { }); it('should navigate and change the setting to off', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), navigateHandler = jasmine.createSpy('navigate'), getContainer = function() { return container; @@ -838,8 +827,7 @@ describe('HtmlReporter', function() { }); describe('UI for hiding disabled specs', function() { it('should be unchecked if not hiding disabled specs', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -863,8 +851,7 @@ describe('HtmlReporter', function() { }); it('should be checked if hiding disabled', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -888,8 +875,7 @@ describe('HtmlReporter', function() { }); it('should not display specs that have been disabled', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -922,8 +908,7 @@ describe('HtmlReporter', function() { }); describe('UI for running tests in random order', function() { it('should be unchecked if not randomizing', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -947,8 +932,7 @@ describe('HtmlReporter', function() { }); it('should be checked if randomizing', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -972,8 +956,7 @@ describe('HtmlReporter', function() { }); it('should navigate and change the setting to on', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), navigateHandler = jasmine.createSpy('navigate'), getContainer = function() { return container; @@ -1001,8 +984,7 @@ describe('HtmlReporter', function() { }); it('should navigate and change the setting to off', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), navigateHandler = jasmine.createSpy('navigate'), getContainer = function() { return container; @@ -1030,8 +1012,7 @@ describe('HtmlReporter', function() { }); it('should show the seed bar if randomizing', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -1061,8 +1042,7 @@ describe('HtmlReporter', function() { }); it('should not show the current seed bar if not randomizing', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -1085,8 +1065,7 @@ describe('HtmlReporter', function() { }); it('should include non-spec query params in the jasmine-skipped link when present', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), reporter = new jasmineUnderTest.HtmlReporter({ env: env, getContainer: function() { @@ -1113,9 +1092,8 @@ describe('HtmlReporter', function() { }); describe('and all specs pass', function() { - var env, container; + var container; beforeEach(function() { - env = new jasmineUnderTest.Env(); container = document.createElement('div'); var getContainer = function() { return container; @@ -1175,9 +1153,8 @@ describe('HtmlReporter', function() { }); describe('and there are excluded specs', function() { - var env, container, reporter, reporterConfig, specStatus; + var container, reporter, reporterConfig, specStatus; beforeEach(function() { - env = new jasmineUnderTest.Env(); container = document.createElement('div'); reporterConfig = { env: env, @@ -1239,9 +1216,8 @@ describe('HtmlReporter', function() { }); describe('and there are pending specs', function() { - var env, container, reporter; + var container, reporter; beforeEach(function() { - env = new jasmineUnderTest.Env(); container = document.createElement('div'); var getContainer = function() { return container; @@ -1297,10 +1273,9 @@ describe('HtmlReporter', function() { }); describe('and some tests fail', function() { - var env, container, reporter; + var container, reporter; beforeEach(function() { - env = new jasmineUnderTest.Env(); container = document.createElement('div'); var getContainer = function() { return container; @@ -1469,8 +1444,7 @@ describe('HtmlReporter', function() { describe('The overall result bar', function() { describe("When the jasmineDone event's overallStatus is 'passed'", function() { it('has class jasmine-passed', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -1500,8 +1474,7 @@ describe('HtmlReporter', function() { describe("When the jasmineDone event's overallStatus is 'failed'", function() { it('has class jasmine-failed', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, @@ -1531,8 +1504,7 @@ describe('HtmlReporter', function() { describe("When the jasmineDone event's overallStatus is 'incomplete'", function() { it('has class jasmine-incomplete', function() { - var env = new jasmineUnderTest.Env(), - container = document.createElement('div'), + var container = document.createElement('div'), getContainer = function() { return container; }, diff --git a/spec/html/MatchersHtmlSpec.js b/spec/html/MatchersHtmlSpec.js index 75256f9d..a1cb8d24 100644 --- a/spec/html/MatchersHtmlSpec.js +++ b/spec/html/MatchersHtmlSpec.js @@ -19,6 +19,10 @@ describe('MatchersSpec - HTML Dependent', function() { }); }); + afterEach(function() { + env.cleanup_(); + }); + function match(value) { return spec.expect(value); } diff --git a/src/core/Env.js b/src/core/Env.js index dc652cd5..6cc9329c 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -1188,6 +1188,12 @@ getJasmineRequireObj().Env = function(j$) { throw new Error(message); } }; + + this.cleanup_ = function() { + if (globalErrors) { + globalErrors.uninstall(); + } + }; } return Env;