Don't leak global error handlers between Jasmine's own tests

This commit is contained in:
Steve Gravrock
2020-01-20 10:18:29 -08:00
parent 6baf3a9270
commit 7f392d188e
21 changed files with 339 additions and 352 deletions

View File

@@ -2100,6 +2100,12 @@ getJasmineRequireObj().Env = function(j$) {
throw new Error(message); throw new Error(message);
} }
}; };
this.cleanup_ = function() {
if (globalErrors) {
globalErrors.uninstall();
}
};
} }
return Env; return Env;

View File

@@ -5,6 +5,10 @@ describe('Env', function() {
env = new jasmineUnderTest.Env(); env = new jasmineUnderTest.Env();
}); });
afterEach(function() {
env.cleanup_();
});
describe('#pending', function() { describe('#pending', function() {
it('throws the Pending Spec exception', function() { it('throws the Pending Spec exception', function() {
expect(function() { expect(function() {
@@ -281,11 +285,13 @@ describe('Env', function() {
it('installs a global error handler on construction', function() { it('installs a global error handler on construction', function() {
var globalErrors = jasmine.createSpyObj('globalErrors', [ var globalErrors = jasmine.createSpyObj('globalErrors', [
'install', 'install',
'uninstall',
'pushListener', 'pushListener',
'popListener' 'popListener'
]); ]);
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors); spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
new jasmineUnderTest.Env(); env.cleanup_();
env = new jasmineUnderTest.Env();
expect(globalErrors.install).toHaveBeenCalled(); expect(globalErrors.install).toHaveBeenCalled();
}); });
}); });
@@ -294,10 +300,12 @@ describe('Env', function() {
it('does not install a global error handler until execute is called', function() { it('does not install a global error handler until execute is called', function() {
var globalErrors = jasmine.createSpyObj('globalErrors', [ var globalErrors = jasmine.createSpyObj('globalErrors', [
'install', 'install',
'uninstall',
'pushListener', 'pushListener',
'popListener' 'popListener'
]); ]);
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors); spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
env.cleanup_();
env = new jasmineUnderTest.Env({ suppressLoadErrors: true }); env = new jasmineUnderTest.Env({ suppressLoadErrors: true });
expect(globalErrors.install).not.toHaveBeenCalled(); expect(globalErrors.install).not.toHaveBeenCalled();
env.execute(); env.execute();

View File

@@ -5,6 +5,10 @@ describe('Exceptions:', function() {
env = new jasmineUnderTest.Env(); env = new jasmineUnderTest.Env();
}); });
afterEach(function() {
env.cleanup_();
});
it('should handle exceptions thrown, but continue', function(done) { it('should handle exceptions thrown, but continue', function(done) {
var secondTest = jasmine.createSpy('second test'); var secondTest = jasmine.createSpy('second test');
env.describe('Suite for handles exceptions', function() { env.describe('Suite for handles exceptions', function() {

View File

@@ -327,52 +327,62 @@ describe('jasmineUnderTest.pp', function() {
expect(jasmineUnderTest.pp(now)).toEqual('Date(' + now.toString() + ')'); expect(jasmineUnderTest.pp(now)).toEqual('Date(' + now.toString() + ')');
}); });
it('should stringify spy objects properly', function() { describe('with a spy object', function() {
var TestObject = { var env;
someFunction: function() {}
},
env = new jasmineUnderTest.Env();
var spyRegistry = new jasmineUnderTest.SpyRegistry({ beforeEach(function() {
currentSpies: function() { env = new jasmineUnderTest.Env();
return [];
},
createSpy: function(name, originalFn) {
return jasmineUnderTest.Spy(name, originalFn);
}
}); });
spyRegistry.spyOn(TestObject, 'someFunction'); afterEach(function() {
expect(jasmineUnderTest.pp(TestObject.someFunction)).toEqual( env.cleanup_();
'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);
}
}); });
spyRegistry.spyOn(TestObject, 'toString'); it('should stringify spy objects properly', function() {
var testSpyObj = env.createSpyObj('TheClassName', ['toString']); var TestObject = {
someFunction: function() {}
};
expect(jasmineUnderTest.pp(testSpyObj)).toEqual( var spyRegistry = new jasmineUnderTest.SpyRegistry({
'spy on TheClassName.toString' 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() { it('should stringify objects that implement jasmineToString', function() {

View File

@@ -5,6 +5,10 @@ describe('Spies', function() {
env = new jasmineUnderTest.Env(); env = new jasmineUnderTest.Env();
}); });
afterEach(function() {
env.cleanup_();
});
describe('createSpy', function() { describe('createSpy', function() {
var TestClass; var TestClass;

View File

@@ -1,28 +1,35 @@
describe('Suite', function() { describe('Suite', function() {
var env;
beforeEach(function() {
env = new jasmineUnderTest.Env();
});
afterEach(function() {
env.cleanup_();
});
it('keeps its id', function() { it('keeps its id', function() {
var env = new jasmineUnderTest.Env(), var suite = new jasmineUnderTest.Suite({
suite = new jasmineUnderTest.Suite({ env: env,
env: env, id: 456,
id: 456, description: 'I am a suite'
description: 'I am a suite' });
});
expect(suite.id).toEqual(456); expect(suite.id).toEqual(456);
}); });
it('returns blank full name for top level suite', function() { it('returns blank full name for top level suite', function() {
var env = new jasmineUnderTest.Env(), var suite = new jasmineUnderTest.Suite({
suite = new jasmineUnderTest.Suite({ env: env,
env: env, description: 'I am a suite'
description: 'I am a suite' });
});
expect(suite.getFullName()).toEqual(''); expect(suite.getFullName()).toEqual('');
}); });
it('returns its full name when it has parent suites', function() { it('returns its full name when it has parent suites', function() {
var env = new jasmineUnderTest.Env(), var parentSuite = new jasmineUnderTest.Suite({
parentSuite = new jasmineUnderTest.Suite({
env: env, env: env,
description: 'I am a parent suite', description: 'I am a parent suite',
parentSuite: jasmine.createSpy('pretend top level 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() { it('adds before functions in order of needed execution', function() {
var env = new jasmineUnderTest.Env(), var suite = new jasmineUnderTest.Suite({
suite = new jasmineUnderTest.Suite({
env: env, env: env,
description: 'I am a suite' description: 'I am a suite'
}), }),
@@ -52,8 +58,7 @@ describe('Suite', function() {
}); });
it('adds after functions in order of needed execution', function() { it('adds after functions in order of needed execution', function() {
var env = new jasmineUnderTest.Env(), var suite = new jasmineUnderTest.Suite({
suite = new jasmineUnderTest.Suite({
env: env, env: env,
description: 'I am a suite' description: 'I am a suite'
}), }),
@@ -115,13 +120,12 @@ describe('Suite', function() {
}); });
it('calls timer to compute duration', function() { it('calls timer to compute duration', function() {
var env = new jasmineUnderTest.Env(), var suite = new jasmineUnderTest.Suite({
suite = new jasmineUnderTest.Suite({ env: env,
env: env, id: 456,
id: 456, description: 'I am a suite',
description: 'I am a suite', timer: jasmine.createSpyObj('timer', { start: null, elapsed: 77000 })
timer: jasmine.createSpyObj('timer', { start: null, elapsed: 77000 }) });
});
suite.startTimer(); suite.startTimer();
suite.endTimer(); suite.endTimer();
expect(suite.getResult().duration).toEqual(77000); expect(suite.getResult().duration).toEqual(77000);

View File

@@ -6,6 +6,10 @@ describe('Custom Async Matchers (Integration)', function() {
env.configure({random: false}); env.configure({random: false});
}); });
afterEach(function() {
env.cleanup_();
});
it('passes the spec if the custom async matcher passes', function(done) { it('passes the spec if the custom async matcher passes', function(done) {
jasmine.getEnv().requirePromises(); jasmine.getEnv().requirePromises();

View File

@@ -7,6 +7,10 @@ describe("Custom Matchers (Integration)", function() {
env.configure({random: false}); env.configure({random: false});
}); });
afterEach(function() {
env.cleanup_();
});
it("allows adding more matchers local to a spec", function(done) { it("allows adding more matchers local to a spec", function(done) {
env.it('spec defining a custom matcher', function() { env.it('spec defining a custom matcher', function() {
env.addMatchers({ env.addMatchers({

View File

@@ -6,6 +6,10 @@ describe('Custom Spy Strategies (Integration)', function() {
env.configure({random: false}); env.configure({random: false});
}); });
afterEach(function() {
env.cleanup_();
});
it('allows adding more strategies local to a suite', function(done) { it('allows adding more strategies local to a suite', function(done) {
var plan = jasmine.createSpy('custom strategy plan') var plan = jasmine.createSpy('custom strategy plan')
.and.returnValue(42); .and.returnValue(42);

View File

@@ -6,6 +6,10 @@ describe('Default Spy Strategy (Integration)', function() {
env.configure({random: false}); env.configure({random: false});
}); });
afterEach(function() {
env.cleanup_();
});
it('allows defining a default spy strategy', function(done) { it('allows defining a default spy strategy', function(done) {
env.describe('suite with default strategy', function() { env.describe('suite with default strategy', function() {
env.beforeEach(function() { env.beforeEach(function() {

View File

@@ -1,11 +1,17 @@
describe("Env integration", function() { describe("Env integration", function() {
var env;
beforeEach(function() { beforeEach(function() {
jasmine.getEnv().registerIntegrationMatchers(); jasmine.getEnv().registerIntegrationMatchers();
env = new jasmineUnderTest.Env();
});
afterEach(function() {
env.cleanup_();
}); });
it("Suites execute as expected (no nesting)", function(done) { it("Suites execute as expected (no nesting)", function(done) {
var env = new jasmineUnderTest.Env(), var calls = [];
calls = [];
var assertions = function() { var assertions = function() {
expect(calls).toEqual([ expect(calls).toEqual([
@@ -32,8 +38,7 @@ describe("Env integration", function() {
}); });
it("Nested Suites execute as expected", function(done) { it("Nested Suites execute as expected", function(done) {
var env = new jasmineUnderTest.Env(), var calls = [];
calls = [];
var assertions = function() { var assertions = function() {
expect(calls).toEqual([ expect(calls).toEqual([
@@ -66,8 +71,7 @@ describe("Env integration", function() {
}); });
it("Multiple top-level Suites execute as expected", function(done) { it("Multiple top-level Suites execute as expected", function(done) {
var env = new jasmineUnderTest.Env(), var calls = [];
calls = [];
var assertions = function() { var assertions = function() {
expect(calls).toEqual([ expect(calls).toEqual([
@@ -108,8 +112,7 @@ describe("Env integration", function() {
}); });
it('explicitly fails a spec', function(done) { it('explicitly fails a spec', function(done) {
var env = new jasmineUnderTest.Env(), var specDone = jasmine.createSpy('specDone');
specDone = jasmine.createSpy('specDone');
env.addReporter({ env.addReporter({
specDone: specDone, 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) { it("produces an understandable error message when 'fail' is used outside of a current spec", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
reporter.jasmineDone.and.callFake(done); reporter.jasmineDone.and.callFake(done);
env.addReporter(reporter); env.addReporter(reporter);
@@ -197,8 +199,6 @@ describe("Env integration", function() {
it("calls associated befores/specs/afters with the same 'this'", function(done) { it("calls associated befores/specs/afters with the same 'this'", function(done) {
var env = new jasmineUnderTest.Env();
env.addReporter({jasmineDone: done}); env.addReporter({jasmineDone: done});
env.configure({random: false}); env.configure({random: false});
env.describe("tests", function() { 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) { 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.addReporter({jasmineDone: done});
env.describe("with an async spec", function() { 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) { it("calls associated beforeAlls/afterAlls only once per suite", function(done) {
var env = new jasmineUnderTest.Env(), var before = jasmine.createSpy('beforeAll'),
before = jasmine.createSpy('beforeAll'),
after = jasmine.createSpy('afterAll'); after = jasmine.createSpy('afterAll');
env.addReporter({ env.addReporter({
@@ -293,8 +290,7 @@ describe("Env integration", function() {
}); });
it("calls associated beforeAlls/afterAlls only once per suite for async", function(done) { it("calls associated beforeAlls/afterAlls only once per suite for async", function(done) {
var env = new jasmineUnderTest.Env(), var before = jasmine.createSpy('beforeAll'),
before = jasmine.createSpy('beforeAll'),
after = jasmine.createSpy('afterAll'); after = jasmine.createSpy('afterAll');
env.addReporter({ env.addReporter({
@@ -332,8 +328,6 @@ describe("Env integration", function() {
}); });
it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) { it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) {
var env = new jasmineUnderTest.Env();
env.addReporter({jasmineDone: done}); env.addReporter({jasmineDone: done});
env.describe("with beforeAll and afterAll", function() { 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) { it("tags top-level afterAll failures with a type", function(done) {
var env = new jasmineUnderTest.Env();
env.addReporter({jasmineDone: function(result) { env.addReporter({jasmineDone: function(result) {
expect(result.failedExpectations[0].globalErrorType).toEqual('afterAll'); expect(result.failedExpectations[0].globalErrorType).toEqual('afterAll');
done(); done();
@@ -403,8 +395,7 @@ describe("Env integration", function() {
}); });
it("does not tag suite afterAll failures with a type", function(done) { it("does not tag suite afterAll failures with a type", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = {
reporter = {
jasmineDone: function() { jasmineDone: function() {
expect(reporter.suiteDone).toHaveBeenCalled(); expect(reporter.suiteDone).toHaveBeenCalled();
done(); done();
@@ -428,8 +419,7 @@ describe("Env integration", function() {
}); });
it("when the beforeAll fails, error at suite level", function (done) { it("when the beforeAll fails, error at suite level", function (done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "suiteDone", "jasmineDone" ]);
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "suiteDone", "jasmineDone" ]);
reporter.jasmineDone.and.callFake(function() { reporter.jasmineDone.and.callFake(function() {
expect(reporter.specDone.calls.count()).toEqual(2); expect(reporter.specDone.calls.count()).toEqual(2);
@@ -465,8 +455,9 @@ describe("Env integration", function() {
clearTimeout: function(fn, delay) { clearTimeout(fn, delay) }, clearTimeout: function(fn, delay) { clearTimeout(fn, delay) },
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
var env = new jasmineUnderTest.Env(), env.cleanup_();
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone", "suiteDone" ]); env = new jasmineUnderTest.Env();
var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone", "suiteDone" ]);
reporter.jasmineDone.and.callFake(function() { reporter.jasmineDone.and.callFake(function() {
expect(reporter.specDone).not.toHaveFailedExpectationsForRunnable('A suite fails', ['fail thrown']); expect(reporter.specDone).not.toHaveFailedExpectationsForRunnable('A suite fails', ['fail thrown']);
@@ -498,8 +489,7 @@ describe("Env integration", function() {
describe('suiteDone reporting', function(){ describe('suiteDone reporting', function(){
it("reports when an afterAll fails an expectation", function(done) { it("reports when an afterAll fails an expectation", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() { reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [ 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) { it("if there are no specs, it still reports correctly", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() { reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer suite', [ expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer suite', [
@@ -553,8 +542,7 @@ describe("Env integration", function() {
}); });
it("reports when afterAll throws an exception", function(done) { it("reports when afterAll throws an exception", function(done) {
var env = new jasmineUnderTest.Env(), var error = new Error('After All Exception'),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() { reporter.jasmineDone.and.callFake(function() {
@@ -579,8 +567,7 @@ describe("Env integration", function() {
}); });
it("reports when an async afterAll fails an expectation", function(done) { it("reports when an async afterAll fails an expectation", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() { reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [ 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) { it("reports when an async afterAll throws an exception", function(done) {
var env = new jasmineUnderTest.Env(), var error = new Error('After All Exception'),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']); reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
@@ -633,8 +619,7 @@ describe("Env integration", function() {
}); });
it('reports expectation failures in global beforeAll', function(done) { it('reports expectation failures in global beforeAll', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']);
reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']);
reporter.jasmineDone.and.callFake(function(results) { reporter.jasmineDone.and.callFake(function(results) {
expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]); 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) { it('reports expectation failures in global afterAll', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj(['jasmineDone']);
reporter = jasmine.createSpyObj(['jasmineDone']);
reporter.jasmineDone.and.callFake(function(results) { reporter.jasmineDone.and.callFake(function(results) {
expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]); 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) { it("Allows specifying which specs and suites to run", function(done) {
var env = new jasmineUnderTest.Env(), var calls = [],
calls = [],
suiteCallback = jasmine.createSpy('suite callback'), suiteCallback = jasmine.createSpy('suite callback'),
firstSpec, firstSpec,
secondSuite; secondSuite;
@@ -714,8 +697,7 @@ describe("Env integration", function() {
}); });
it('runs before and after all functions for runnables provided to .execute()', function(done) { it('runs before and after all functions for runnables provided to .execute()', function(done) {
var env = new jasmineUnderTest.Env(), var calls = [],
calls = [],
first_spec, first_spec,
second_spec; second_spec;
@@ -750,8 +732,7 @@ describe("Env integration", function() {
}); });
it("Allows filtering out specs and suites to run programmatically", function(done) { it("Allows filtering out specs and suites to run programmatically", function(done) {
var env = new jasmineUnderTest.Env(), var calls = [],
calls = [],
suiteCallback = jasmine.createSpy('suite callback'), suiteCallback = jasmine.createSpy('suite callback'),
firstSpec, firstSpec,
secondSuite; secondSuite;
@@ -793,8 +774,6 @@ describe("Env integration", function() {
}); });
it("Functions can be spied on and have their calls tracked", function (done) { it("Functions can be spied on and have their calls tracked", function (done) {
var env = new jasmineUnderTest.Env();
var originalFunctionWasCalled = false; var originalFunctionWasCalled = false;
var subject = { var subject = {
spiedFunc: function() { spiedFunc: function() {
@@ -833,8 +812,7 @@ describe("Env integration", function() {
}); });
it('can be configured to allow respying on functions', function (done) { it('can be configured to allow respying on functions', function (done) {
var env = new jasmineUnderTest.Env(), var foo = {
foo = {
bar: function () { bar: function () {
return 1; 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) { it('removes all spies added in a spec after the spec is complete', function(done) {
var env = new jasmineUnderTest.Env(), var originalFoo = function() {},
originalFoo = function() {},
testObj = { testObj = {
foo: originalFoo 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) { it('removes all spies added in a suite after the suite is complete', function(done) {
var env = new jasmineUnderTest.Env(), var originalFoo = function() {},
originalFoo = function() {},
testObj = { testObj = {
foo: originalFoo 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) { it('removes a spy from the top suite after the run is complete', function(done) {
var env = new jasmineUnderTest.Env(), var originalFoo = function() {},
originalFoo = function() {},
testObj = { testObj = {
foo: originalFoo foo: originalFoo
}; };
@@ -944,8 +919,10 @@ describe("Env integration", function() {
it("Mock clock can be installed and used in tests", function(done) { 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); }), var globalSetTimeout = jasmine.createSpy('globalSetTimeout').and.callFake(function(cb, t) { setTimeout(cb, t); }),
delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'), delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'),
delayedFunctionForMockClock = jasmine.createSpy('delayedFunctionForMockClock'), delayedFunctionForMockClock = jasmine.createSpy('delayedFunctionForMockClock');
env = new jasmineUnderTest.Env({global: { setTimeout: globalSetTimeout, clearTimeout: clearTimeout, setImmediate: function(cb) { setTimeout(cb, 0); } }});
env.cleanup_();
env = new jasmineUnderTest.Env({global: { setTimeout: globalSetTimeout, clearTimeout: clearTimeout, setImmediate: function(cb) { setTimeout(cb, 0); } }});
var assertions = function() { var assertions = function() {
expect(delayedFunctionForMockClock).toHaveBeenCalled(); 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) { it("should run async specs in order, waiting for them to complete", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone']),
reporter = jasmine.createSpyObj('reporter', ['jasmineDone']),
mutatedVar; mutatedVar;
reporter.jasmineDone.and.callFake(function() { reporter.jasmineDone.and.callFake(function() {
@@ -1008,9 +984,10 @@ describe("Env integration", function() {
describe("with a mock clock", function() { describe("with a mock clock", function() {
var realSetTimeout; var realSetTimeout;
function createMockedEnv() { function createMockedEnv() {
env.cleanup_();
// explicitly pass in timing functions so we can make sure that clear stack always works // 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 // no matter how long the suite in the spec is
return new jasmineUnderTest.Env({ global: { env = new jasmineUnderTest.Env({ global: {
setTimeout: function(cb, t) { setTimeout: function(cb, t) {
var stack = jasmine.util.errorWithStack().stack; var stack = jasmine.util.errorWithStack().stack;
if (stack.indexOf('ClearStack') >= 0) { 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) { it("should wait a default interval before failing specs that haven't called done yet", function(done) {
var env = createMockedEnv(), createMockedEnv();
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]); var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
reporter.specDone.and.callFake(function(result) { reporter.specDone.and.callFake(function(result) {
expect(result).toEqual(jasmine.objectContaining({status: 'failed'})); 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){ it("should not use the mock clock for asynchronous timeouts", function(done){
var env = createMockedEnv(), createMockedEnv();
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]), var reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]),
clock = env.clock; clock = env.clock;
reporter.specDone.and.callFake(function() { 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) { it('should wait a custom interval before reporting async functions that fail to complete', function(done) {
var env = createMockedEnv(), createMockedEnv();
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']); var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(r) { reporter.jasmineDone.and.callFake(function(r) {
expect(r.failedExpectations).toEqual([]); expect(r.failedExpectations).toEqual([]);
@@ -1207,8 +1184,7 @@ describe("Env integration", function() {
}); });
it('explicitly fails an async spec', function(done) { it('explicitly fails an async spec', function(done) {
var env = new jasmineUnderTest.Env(), var specDone = jasmine.createSpy('specDone');
specDone = jasmine.createSpy('specDone');
env.addReporter({ env.addReporter({
specDone: specDone, specDone: specDone,
@@ -1273,8 +1249,7 @@ describe("Env integration", function() {
describe('focused tests', function() { describe('focused tests', function() {
it('should only run the focused tests', function(done) { it('should only run the focused tests', function(done) {
var env = new jasmineUnderTest.Env(), var calls = [];
calls = [];
var assertions = function() { var assertions = function() {
expect(calls).toEqual(['focused']); expect(calls).toEqual(['focused']);
@@ -1297,8 +1272,7 @@ describe("Env integration", function() {
}); });
it('should only run focused suites', function(done){ it('should only run focused suites', function(done){
var env = new jasmineUnderTest.Env(), var calls = [];
calls = [];
var assertions = function() { var assertions = function() {
expect(calls).toEqual(['focused']); expect(calls).toEqual(['focused']);
@@ -1323,8 +1297,7 @@ describe("Env integration", function() {
}); });
it('should run focused tests inside an xdescribe', function(done) { it('should run focused tests inside an xdescribe', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted", "jasmineStarted",
"jasmineDone", "jasmineDone",
"suiteStarted", "suiteStarted",
@@ -1359,8 +1332,7 @@ describe("Env integration", function() {
}); });
it('should run focused suites inside an xdescribe', function(done) { it('should run focused suites inside an xdescribe', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted", "jasmineStarted",
"jasmineDone", "jasmineDone",
"suiteStarted", "suiteStarted",
@@ -1398,8 +1370,7 @@ describe("Env integration", function() {
}); });
it("should report as expected", function(done) { it("should report as expected", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted", "jasmineStarted",
"jasmineDone", "jasmineDone",
"suiteStarted", "suiteStarted",
@@ -1472,8 +1443,7 @@ describe("Env integration", function() {
}); });
it("should report the random seed at the beginning and end of execution", function(done) { it("should report the random seed at the beginning and end of execution", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted", "jasmineStarted",
"jasmineDone", "jasmineDone",
"suiteStarted", "suiteStarted",
@@ -1500,8 +1470,7 @@ describe("Env integration", function() {
}); });
it('should report pending spec messages', function(done) { it('should report pending spec messages', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
'specDone', 'specDone',
'jasmineDone' 'jasmineDone'
]); ]);
@@ -1537,8 +1506,7 @@ describe("Env integration", function() {
reject(this.exception); reject(this.exception);
}; };
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
'specDone', 'specDone',
'jasmineDone' 'jasmineDone'
]); ]);
@@ -1564,8 +1532,7 @@ describe("Env integration", function() {
}); });
it('should report using fallback reporter', function(done) { it('should report using fallback reporter', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
'specDone', 'specDone',
'jasmineDone' 'jasmineDone'
]); ]);
@@ -1586,8 +1553,7 @@ describe("Env integration", function() {
}); });
it('should report xdescribes as expected', function(done) { it('should report xdescribes as expected', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted", "jasmineStarted",
"jasmineDone", "jasmineDone",
"suiteStarted", "suiteStarted",
@@ -1627,8 +1593,7 @@ describe("Env integration", function() {
}); });
it("should be possible to get full name from a spec", function() { it("should be possible to get full name from a spec", function() {
var env = new jasmineUnderTest.Env(), var topLevelSpec, nestedSpec, doublyNestedSpec;
topLevelSpec, nestedSpec, doublyNestedSpec;
env.describe("my tests", function() { env.describe("my tests", function() {
topLevelSpec = env.it("are sometimes top level", 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) { it("Custom equality testers should be per spec", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineDone", "jasmineDone",
"specDone" "specDone"
]); ]);
@@ -1683,8 +1647,7 @@ describe("Env integration", function() {
}); });
it("Custom equality testers should be per suite", function(done) { it("Custom equality testers should be per suite", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineDone", "jasmineDone",
"specDone" "specDone"
]); ]);
@@ -1726,8 +1689,7 @@ describe("Env integration", function() {
}); });
it("Custom equality testers for toContain should be per spec", function(done) { it("Custom equality testers for toContain should be per spec", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineDone", "jasmineDone",
"specDone" "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) { it("produces an understandable error message when an 'expect' is used outside of a current spec", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
reporter.jasmineDone.and.callFake(done); reporter.jasmineDone.and.callFake(done);
env.addReporter(reporter); env.addReporter(reporter);
@@ -1777,8 +1738,7 @@ describe("Env integration", function() {
}); });
it("Custom equality testers for toContain should be per suite", function(done) { it("Custom equality testers for toContain should be per suite", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReporter', [
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineDone", "jasmineDone",
"specDone" "specDone"
]); ]);
@@ -1820,8 +1780,7 @@ describe("Env integration", function() {
}); });
it("Custom matchers should be per spec", function(done) { it("Custom matchers should be per spec", function(done) {
var env = new jasmineUnderTest.Env(), var matchers = {
matchers = {
toFoo: function() {} toFoo: function() {}
}; };
@@ -1842,8 +1801,7 @@ describe("Env integration", function() {
}); });
it("Custom matchers should be per suite", function(done) { it("Custom matchers should be per suite", function(done) {
var env = new jasmineUnderTest.Env(), var matchers = {
matchers = {
toFoo: function() {} 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) { it('throws an exception if you try to create a spy outside of a runnable', function (done) {
var env = new jasmineUnderTest.Env(), var obj = {fn: function () {}},
obj = {fn: function () {}},
exception; exception;
env.describe("a suite", function () { 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) { it('throws an exception if you try to add a matcher outside of a runnable', function (done) {
var env = new jasmineUnderTest.Env(), var obj = {fn: function () {}},
obj = {fn: function () {}},
exception; exception;
env.describe("a suite", function () { 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) { it('throws an exception if you try to add a custom equality outside of a runnable', function (done) {
var env = new jasmineUnderTest.Env(), var obj = {fn: function () {}},
obj = {fn: function () {}},
exception; exception;
env.describe("a suite", function () { 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) { it("should associate errors thrown from async code with the correct runnable", function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone','specDone']);
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone','specDone']);
reporter.jasmineDone.and.callFake(function() { reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('async suite', [ 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) { it('should throw on suites/specs/befores/afters nested in methods other than \'describe\'', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function() { reporter.jasmineDone.and.callFake(function() {
var msg = /\'.*\' should only be used in \'describe\' function/; var msg = /\'.*\' should only be used in \'describe\' function/;
@@ -2037,11 +1990,13 @@ describe("Env integration", function() {
var global = { var global = {
setTimeout: function(fn, delay) { setTimeout(fn, delay) }, setTimeout: function(fn, delay) { setTimeout(fn, delay) },
clearTimeout: function(fn, delay) { clearTimeout(fn, delay) }, clearTimeout: function(fn, delay) { clearTimeout(fn, delay) },
onerror: function() {}
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
var env = new jasmineUnderTest.Env(), env.cleanup_();
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); env = new jasmineUnderTest.Env();
var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.failedExpectations).toEqual([ expect(e.failedExpectations).toEqual([
@@ -2087,8 +2042,9 @@ describe("Env integration", function() {
globalErrors.pushListener(onerror); globalErrors.pushListener(onerror);
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors); spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
var env = new jasmineUnderTest.Env({suppressLoadErrors: true}); env.cleanup_();
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); env = new jasmineUnderTest.Env({suppressLoadErrors: true});
var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.failedExpectations).toEqual([]); expect(e.failedExpectations).toEqual([]);
@@ -2106,8 +2062,7 @@ describe("Env integration", function() {
describe('Overall status in the jasmineDone event', function() { describe('Overall status in the jasmineDone event', function() {
describe('When everything passes', function() { describe('When everything passes', function() {
it('is "passed"', function(done) { it('is "passed"', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('passed'); expect(e.overallStatus).toEqual('passed');
@@ -2122,8 +2077,7 @@ describe("Env integration", function() {
describe('When a spec fails', function() { describe('When a spec fails', function() {
it('is "failed"', function(done) { it('is "failed"', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('failed'); expect(e.overallStatus).toEqual('failed');
@@ -2139,10 +2093,9 @@ describe("Env integration", function() {
}); });
describe('when spec has no expectations', function() { describe('when spec has no expectations', function() {
var env, reporter; var reporter;
beforeEach(function() { beforeEach(function() {
env = new jasmineUnderTest.Env();
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
env.addReporter(reporter); env.addReporter(reporter);
@@ -2175,8 +2128,7 @@ describe("Env integration", function() {
describe('When a top-level beforeAll fails', function() { describe('When a top-level beforeAll fails', function() {
it('is "failed"', function(done) { it('is "failed"', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('failed'); expect(e.overallStatus).toEqual('failed');
@@ -2194,8 +2146,7 @@ describe("Env integration", function() {
describe('When a suite beforeAll fails', function() { describe('When a suite beforeAll fails', function() {
it('is "failed"', function(done) { it('is "failed"', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('failed'); expect(e.overallStatus).toEqual('failed');
@@ -2215,8 +2166,7 @@ describe("Env integration", function() {
describe('When a top-level afterAll fails', function() { describe('When a top-level afterAll fails', function() {
it('is "failed"', function(done) { it('is "failed"', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('failed'); expect(e.overallStatus).toEqual('failed');
@@ -2234,8 +2184,7 @@ describe("Env integration", function() {
describe('When a suite afterAll fails', function() { describe('When a suite afterAll fails', function() {
it('is "failed"', function(done) { it('is "failed"', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('failed'); expect(e.overallStatus).toEqual('failed');
@@ -2261,7 +2210,8 @@ describe("Env integration", function() {
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); 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']); var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
@@ -2278,8 +2228,7 @@ describe("Env integration", function() {
describe('When there are no specs', function() { describe('When there are no specs', function() {
it('is "incomplete"', function(done) { it('is "incomplete"', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('incomplete'); expect(e.overallStatus).toEqual('incomplete');
@@ -2294,8 +2243,7 @@ describe("Env integration", function() {
describe('When a spec is focused', function() { describe('When a spec is focused', function() {
it('is "incomplete"', function(done) { it('is "incomplete"', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('incomplete'); expect(e.overallStatus).toEqual('incomplete');
@@ -2311,8 +2259,7 @@ describe("Env integration", function() {
describe('When a suite is focused', function() { describe('When a suite is focused', function() {
it('is "incomplete"', function(done) { it('is "incomplete"', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('incomplete'); expect(e.overallStatus).toEqual('incomplete');
@@ -2330,8 +2277,7 @@ describe("Env integration", function() {
describe('When there are both failures and focused specs', function() { describe('When there are both failures and focused specs', function() {
it('is "failed"', function(done) { it('is "failed"', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('failed'); 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) { it('should report deprecation warnings on the correct specs and suites', function(done) {
var env = new jasmineUnderTest.Env(), var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
// prevent deprecation from being displayed // prevent deprecation from being displayed
spyOn(console, "error"); spyOn(console, "error");
@@ -2395,8 +2340,7 @@ describe("Env integration", function() {
}); });
it('should report deprecation stack with an error object', function(done) { it('should report deprecation stack with an error object', function(done) {
var env = new jasmineUnderTest.Env(), var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']), reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']),
topLevelError, suiteLevelError, specLevelError; topLevelError, suiteLevelError, specLevelError;
@@ -2458,8 +2402,7 @@ describe("Env integration", function() {
it('supports async matchers', function(done) { it('supports async matchers', function(done) {
jasmine.getEnv().requirePromises(); jasmine.getEnv().requirePromises();
var env = new jasmineUnderTest.Env(), var specDone = jasmine.createSpy('specDone'),
specDone = jasmine.createSpy('specDone'),
suiteDone = jasmine.createSpy('suiteDone'); suiteDone = jasmine.createSpy('suiteDone');
env.addReporter({ env.addReporter({
@@ -2507,8 +2450,7 @@ describe("Env integration", function() {
it('provides custom equality testers to async matchers', function(done) { it('provides custom equality testers to async matchers', function(done) {
jasmine.getEnv().requirePromises(); jasmine.getEnv().requirePromises();
var env = new jasmineUnderTest.Env(), var specDone = jasmine.createSpy('specDone');
specDone = jasmine.createSpy('specDone');
env.addReporter({ env.addReporter({
specDone: specDone, specDone: specDone,
@@ -2533,8 +2475,7 @@ describe("Env integration", function() {
it('includes useful stack frames in async matcher failures', function(done) { it('includes useful stack frames in async matcher failures', function(done) {
jasmine.getEnv().requirePromises(); jasmine.getEnv().requirePromises();
var env = new jasmineUnderTest.Env(), var specDone = jasmine.createSpy('specDone');
specDone = jasmine.createSpy('specDone');
env.addReporter({ env.addReporter({
specDone: specDone, 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) { it('reports an error when an async expectation occurs after the spec finishes', function(done) {
jasmine.getEnv().requirePromises(); jasmine.getEnv().requirePromises();
var env = new jasmineUnderTest.Env(), var resolve,
resolve,
promise = new Promise(function(res) { resolve = res; }); promise = new Promise(function(res) { resolve = res; });
env.describe('a suite', function() { 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) { it('reports an error when an async expectation occurs after the suite finishes', function(done) {
jasmine.getEnv().requirePromises(); jasmine.getEnv().requirePromises();
var env = new jasmineUnderTest.Env(), var resolve,
resolve,
promise = new Promise(function(res) { resolve = res; }); promise = new Promise(function(res) { resolve = res; });
env.describe('a suite', function() { env.describe('a suite', function() {

View File

@@ -1,7 +1,16 @@
describe('Matchers (Integration)', function() { describe('Matchers (Integration)', function() {
var env;
beforeEach(function() {
env = new jasmineUnderTest.Env();
});
afterEach(function() {
env.cleanup_();
});
function verifyPasses(expectations) { function verifyPasses(expectations) {
it('passes', function(done) { it('passes', function(done) {
var env = new jasmineUnderTest.Env();
env.it('a spec', function() { env.it('a spec', function() {
expectations(env); expectations(env);
}); });
@@ -26,7 +35,6 @@ describe('Matchers (Integration)', function() {
function verifyFails(expectations) { function verifyFails(expectations) {
it('fails', function(done) { it('fails', function(done) {
var env = new jasmineUnderTest.Env();
env.it('a spec', function() { env.it('a spec', function() {
expectations(env); expectations(env);
}); });
@@ -51,7 +59,6 @@ describe('Matchers (Integration)', function() {
function verifyPassesAsync(expectations) { function verifyPassesAsync(expectations) {
it('passes', function(done) { it('passes', function(done) {
jasmine.getEnv().requirePromises(); jasmine.getEnv().requirePromises();
var env = new jasmineUnderTest.Env();
env.it('a spec', function() { env.it('a spec', function() {
return expectations(env); return expectations(env);
@@ -77,7 +84,6 @@ describe('Matchers (Integration)', function() {
function verifyFailsAsync(expectations) { function verifyFailsAsync(expectations) {
it('fails', function(done) { it('fails', function(done) {
var env = new jasmineUnderTest.Env();
jasmine.getEnv().requirePromises(); jasmine.getEnv().requirePromises();
env.it('a spec', function() { env.it('a spec', function() {

View File

@@ -7,6 +7,10 @@ describe("spec running", function () {
env.configure({random: false}); env.configure({random: false});
}); });
afterEach(function() {
env.cleanup_();
});
it('should assign spec ids sequentially', function() { it('should assign spec ids sequentially', function() {
var it0, it1, it2, it3, it4; var it0, it1, it2, it3, it4;
env.describe('test suite', function() { env.describe('test suite', function() {

View File

@@ -678,7 +678,6 @@ describe("matchersUtil", function() {
}, },
diffBuilder = jasmine.createSpyObj('diffBuilder', ['record', 'withPath']); diffBuilder = jasmine.createSpyObj('diffBuilder', ['record', 'withPath']);
diffBuilder.withPath.and.callFake(function(p, block) { block() }); diffBuilder.withPath.and.callFake(function(p, block) { block() });
debugger;
jasmineUnderTest.matchersUtil.equals({x: 42}, {x: tester}, [], diffBuilder); jasmineUnderTest.matchersUtil.equals({x: 42}, {x: tester}, [], diffBuilder);
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function)); expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
@@ -693,7 +692,6 @@ describe("matchersUtil", function() {
}, },
diffBuilder = jasmine.createSpyObj('diffBuilder', ['record', 'withPath']); diffBuilder = jasmine.createSpyObj('diffBuilder', ['record', 'withPath']);
diffBuilder.withPath.and.callFake(function(p, block) { block() }); diffBuilder.withPath.and.callFake(function(p, block) { block() });
debugger;
jasmineUnderTest.matchersUtil.equals({x: 42}, {x: tester}, [], diffBuilder); jasmineUnderTest.matchersUtil.equals({x: 42}, {x: tester}, [], diffBuilder);
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function)); expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));

View File

@@ -1,24 +1,30 @@
describe("toHaveBeenCalledBefore", function() { describe("toHaveBeenCalledBefore", function () {
it("throws an exception when the actual is not a spy", function() { it("throws an exception when the actual is not a spy", function () {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
fn = function() {}, fn = function () {
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'); },
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(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), spy = new jasmineUnderTest.Spy('a spy'),
fn = function() {}; 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(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), firstSpy = new jasmineUnderTest.Spy('first spy'),
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'); secondSpy = new jasmineUnderTest.Spy('second spy');
secondSpy(); secondSpy();
@@ -27,10 +33,10 @@ describe("toHaveBeenCalledBefore", function() {
expect(result.message).toMatch(/Expected spy first spy to have been called./); 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(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), firstSpy = new jasmineUnderTest.Spy('first spy'),
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'); secondSpy = new jasmineUnderTest.Spy('second spy');
firstSpy(); firstSpy();
@@ -39,11 +45,11 @@ describe("toHaveBeenCalledBefore", function() {
expect(result.message).toMatch(/Expected spy second spy to have been called./); 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(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), firstSpy = new jasmineUnderTest.Spy('first spy'),
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'), secondSpy = new jasmineUnderTest.Spy('second spy'),
result; result;
secondSpy(); secondSpy();
firstSpy(); firstSpy();
@@ -53,11 +59,11 @@ describe("toHaveBeenCalledBefore", function() {
expect(result.message).toEqual('Expected spy first spy to have been called before spy second spy'); 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(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), firstSpy = new jasmineUnderTest.Spy('first spy'),
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'), secondSpy = new jasmineUnderTest.Spy('second spy'),
result; result;
firstSpy(); firstSpy();
secondSpy(); 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)'); 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(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), firstSpy = new jasmineUnderTest.Spy('first spy'),
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'), secondSpy = new jasmineUnderTest.Spy('second spy'),
result; result;
secondSpy(); secondSpy();
firstSpy(); 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)'); 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(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'), firstSpy = new jasmineUnderTest.Spy('first spy'),
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'), secondSpy = new jasmineUnderTest.Spy('second spy'),
result; result;
firstSpy(); firstSpy();
secondSpy(); secondSpy();

View File

@@ -1,7 +1,7 @@
describe("toHaveBeenCalled", function() { describe("toHaveBeenCalled", function() {
it("passes when the actual was called, with a custom .not fail message", function() { it("passes when the actual was called, with a custom .not fail message", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'), calledSpy = new jasmineUnderTest.Spy('called-spy'),
result; result;
calledSpy(); calledSpy();
@@ -13,7 +13,7 @@ describe("toHaveBeenCalled", function() {
it("fails when the actual was not called", function() { it("fails when the actual was not called", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'), uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
result; result;
result = matcher.compare(uncalledSpy); result = matcher.compare(uncalledSpy);
@@ -29,14 +29,14 @@ describe("toHaveBeenCalled", function() {
it("throws an exception when invoked with any arguments", function() { it("throws an exception when invoked with any arguments", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(), 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/); expect(function() { matcher.compare(spy, 'foo') }).toThrowError(Error, /Does not take arguments, use toHaveBeenCalledWith/);
}); });
it("has a custom message on failure", function() { it("has a custom message on failure", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
spy = new jasmineUnderTest.Env().createSpy('sample-spy'), spy = new jasmineUnderTest.Spy('sample-spy'),
result; result;
result = matcher.compare(spy); result = matcher.compare(spy);

View File

@@ -1,14 +1,14 @@
describe("toHaveBeenCalledTimes", function() { describe("toHaveBeenCalledTimes", function() {
it("passes when the actual 0 matches the expected 0 ", function () { it("passes when the actual 0 matches the expected 0 ", function () {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'), calledSpy = new jasmineUnderTest.Spy('called-spy'),
result; result;
result = matcher.compare(calledSpy, 0); result = matcher.compare(calledSpy, 0);
expect(result.pass).toBeTruthy(); expect(result.pass).toBeTruthy();
}); });
it("passes when the actual matches the expected", function() { it("passes when the actual matches the expected", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'), calledSpy = new jasmineUnderTest.Spy('called-spy'),
result; result;
calledSpy(); calledSpy();
@@ -18,7 +18,7 @@ describe("toHaveBeenCalledTimes", function() {
it("fails when expected numbers is not supplied", function(){ it("fails when expected numbers is not supplied", function(){
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
spy = new jasmineUnderTest.Env().createSpy('spy'), spy = new jasmineUnderTest.Spy('spy'),
result; result;
spy(); spy();
@@ -29,7 +29,7 @@ describe("toHaveBeenCalledTimes", function() {
it("fails when the actual was called less than the expected", function() { it("fails when the actual was called less than the expected", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'), uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
result; result;
result = matcher.compare(uncalledSpy, 2); result = matcher.compare(uncalledSpy, 2);
@@ -38,7 +38,7 @@ describe("toHaveBeenCalledTimes", function() {
it("fails when the actual was called more than expected", function() { it("fails when the actual was called more than expected", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'), uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
result; result;
uncalledSpy(); uncalledSpy();
@@ -59,7 +59,7 @@ describe("toHaveBeenCalledTimes", function() {
it("has a custom message on failure that tells it was called only once", function() { it("has a custom message on failure that tells it was called only once", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
spy = new jasmineUnderTest.Env().createSpy('sample-spy'), spy = new jasmineUnderTest.Spy('sample-spy'),
result; result;
spy(); spy();
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() { it("has a custom message on failure that tells how many times it was called", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(), var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
spy = new jasmineUnderTest.Env().createSpy('sample-spy'), spy = new jasmineUnderTest.Spy('sample-spy'),
result; result;
spy(); spy();
spy(); spy();

View File

@@ -5,7 +5,7 @@ describe("toHaveBeenCalledWith", function() {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true) contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
}, },
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util), matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'), calledSpy = new jasmineUnderTest.Spy('called-spy'),
result; result;
calledSpy('a', 'b'); calledSpy('a', 'b');
@@ -21,7 +21,7 @@ describe("toHaveBeenCalledWith", function() {
}, },
customEqualityTesters = [function() { return true; }], customEqualityTesters = [function() { return true; }],
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util, customEqualityTesters), matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util, customEqualityTesters),
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'); calledSpy = new jasmineUnderTest.Spy('called-spy');
calledSpy('a', 'b'); calledSpy('a', 'b');
matcher.compare(calledSpy, 'a', 'b'); matcher.compare(calledSpy, 'a', 'b');
@@ -34,7 +34,7 @@ describe("toHaveBeenCalledWith", function() {
contains: jasmine.createSpy('delegated-contains').and.returnValue(false) contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
}, },
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util), matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'), uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
result; result;
result = matcher.compare(uncalledSpy); result = matcher.compare(uncalledSpy);
@@ -45,7 +45,7 @@ describe("toHaveBeenCalledWith", function() {
it("fails when the actual was called with different parameters", function() { it("fails when the actual was called with different parameters", function() {
var util = jasmineUnderTest.matchersUtil, var util = jasmineUnderTest.matchersUtil,
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util), matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
calledSpy = new jasmineUnderTest.Env().createSpy('called spy'), calledSpy = new jasmineUnderTest.Spy('called spy'),
result; result;
calledSpy('a'); calledSpy('a');

View File

@@ -1,7 +1,16 @@
describe('HtmlReporter', function() { 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() { it('builds the initial DOM elements, including the title banner', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -37,8 +46,7 @@ describe('HtmlReporter', function() {
}); });
it('builds a single reporter even if initialized multiple times', function() { it('builds a single reporter even if initialized multiple times', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -71,7 +79,7 @@ describe('HtmlReporter', function() {
container = document.createElement('div'); container = document.createElement('div');
reporter = new jasmineUnderTest.HtmlReporter({ reporter = new jasmineUnderTest.HtmlReporter({
env: new jasmineUnderTest.Env(), env: env,
getContainer: function() { getContainer: function() {
return container; return container;
}, },
@@ -119,8 +127,7 @@ describe('HtmlReporter', function() {
}); });
it('reports the status symbol of a excluded spec', function() { it('reports the status symbol of a excluded spec', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -152,8 +159,7 @@ describe('HtmlReporter', function() {
}); });
it('reports the status symbol of a pending spec', function() { it('reports the status symbol of a pending spec', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -182,8 +188,7 @@ describe('HtmlReporter', function() {
}); });
it('reports the status symbol of a passing spec', function() { it('reports the status symbol of a passing spec', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -213,8 +218,7 @@ describe('HtmlReporter', function() {
}); });
it('reports the status symbol of a failing spec', function() { it('reports the status symbol of a failing spec', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -246,8 +250,7 @@ describe('HtmlReporter', function() {
describe('when there are deprecation warnings', function() { describe('when there are deprecation warnings', function() {
it('displays the messages in their own alert bars', function() { it('displays the messages in their own alert bars', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -298,8 +301,7 @@ describe('HtmlReporter', function() {
if (!window.console) { if (!window.console) {
window.console = { error: function() {} }; window.console = { error: function() {} };
} }
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -343,8 +345,7 @@ describe('HtmlReporter', function() {
}); });
it('reports the run time', function() { it('reports the run time', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -372,8 +373,7 @@ describe('HtmlReporter', function() {
}); });
it('reports the suite and spec names with status', function() { it('reports the suite and spec names with status', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -490,8 +490,7 @@ describe('HtmlReporter', function() {
}); });
it('has an options menu', function() { it('has an options menu', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -529,8 +528,7 @@ describe('HtmlReporter', function() {
describe('when there are global errors', function() { describe('when there are global errors', function() {
it('displays the exceptions in their own alert bars', function() { it('displays the exceptions in their own alert bars', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -576,8 +574,7 @@ describe('HtmlReporter', function() {
}); });
it('displays file and line information if available', function() { it('displays file and line information if available', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -619,8 +616,7 @@ describe('HtmlReporter', function() {
describe('UI for stop on spec failure', function() { describe('UI for stop on spec failure', function() {
it('should be unchecked for full execution', function() { it('should be unchecked for full execution', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -643,8 +639,7 @@ describe('HtmlReporter', function() {
}); });
it('should be checked if stopping short', function() { it('should be checked if stopping short', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -669,8 +664,7 @@ describe('HtmlReporter', function() {
}); });
it('should navigate and turn the setting on', function() { it('should navigate and turn the setting on', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
navigationHandler = jasmine.createSpy('navigate'), navigationHandler = jasmine.createSpy('navigate'),
getContainer = function() { getContainer = function() {
return container; return container;
@@ -697,8 +691,7 @@ describe('HtmlReporter', function() {
}); });
it('should navigate and turn the setting off', function() { it('should navigate and turn the setting off', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
navigationHandler = jasmine.createSpy('navigate'), navigationHandler = jasmine.createSpy('navigate'),
getContainer = function() { getContainer = function() {
return container; return container;
@@ -729,8 +722,7 @@ describe('HtmlReporter', function() {
describe('UI for throwing errors on expectation failures', function() { describe('UI for throwing errors on expectation failures', function() {
it('should be unchecked if not throwing', function() { it('should be unchecked if not throwing', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -753,8 +745,7 @@ describe('HtmlReporter', function() {
}); });
it('should be checked if throwing', function() { it('should be checked if throwing', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -779,8 +770,7 @@ describe('HtmlReporter', function() {
}); });
it('should navigate and change the setting to on', function() { it('should navigate and change the setting to on', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
navigateHandler = jasmine.createSpy('navigate'), navigateHandler = jasmine.createSpy('navigate'),
getContainer = function() { getContainer = function() {
return container; return container;
@@ -807,8 +797,7 @@ describe('HtmlReporter', function() {
}); });
it('should navigate and change the setting to off', function() { it('should navigate and change the setting to off', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
navigateHandler = jasmine.createSpy('navigate'), navigateHandler = jasmine.createSpy('navigate'),
getContainer = function() { getContainer = function() {
return container; return container;
@@ -838,8 +827,7 @@ describe('HtmlReporter', function() {
}); });
describe('UI for hiding disabled specs', function() { describe('UI for hiding disabled specs', function() {
it('should be unchecked if not hiding disabled specs', function() { it('should be unchecked if not hiding disabled specs', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -863,8 +851,7 @@ describe('HtmlReporter', function() {
}); });
it('should be checked if hiding disabled', function() { it('should be checked if hiding disabled', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -888,8 +875,7 @@ describe('HtmlReporter', function() {
}); });
it('should not display specs that have been disabled', function() { it('should not display specs that have been disabled', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -922,8 +908,7 @@ describe('HtmlReporter', function() {
}); });
describe('UI for running tests in random order', function() { describe('UI for running tests in random order', function() {
it('should be unchecked if not randomizing', function() { it('should be unchecked if not randomizing', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -947,8 +932,7 @@ describe('HtmlReporter', function() {
}); });
it('should be checked if randomizing', function() { it('should be checked if randomizing', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -972,8 +956,7 @@ describe('HtmlReporter', function() {
}); });
it('should navigate and change the setting to on', function() { it('should navigate and change the setting to on', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
navigateHandler = jasmine.createSpy('navigate'), navigateHandler = jasmine.createSpy('navigate'),
getContainer = function() { getContainer = function() {
return container; return container;
@@ -1001,8 +984,7 @@ describe('HtmlReporter', function() {
}); });
it('should navigate and change the setting to off', function() { it('should navigate and change the setting to off', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
navigateHandler = jasmine.createSpy('navigate'), navigateHandler = jasmine.createSpy('navigate'),
getContainer = function() { getContainer = function() {
return container; return container;
@@ -1030,8 +1012,7 @@ describe('HtmlReporter', function() {
}); });
it('should show the seed bar if randomizing', function() { it('should show the seed bar if randomizing', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -1061,8 +1042,7 @@ describe('HtmlReporter', function() {
}); });
it('should not show the current seed bar if not randomizing', function() { it('should not show the current seed bar if not randomizing', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -1085,8 +1065,7 @@ describe('HtmlReporter', function() {
}); });
it('should include non-spec query params in the jasmine-skipped link when present', function() { it('should include non-spec query params in the jasmine-skipped link when present', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
reporter = new jasmineUnderTest.HtmlReporter({ reporter = new jasmineUnderTest.HtmlReporter({
env: env, env: env,
getContainer: function() { getContainer: function() {
@@ -1113,9 +1092,8 @@ describe('HtmlReporter', function() {
}); });
describe('and all specs pass', function() { describe('and all specs pass', function() {
var env, container; var container;
beforeEach(function() { beforeEach(function() {
env = new jasmineUnderTest.Env();
container = document.createElement('div'); container = document.createElement('div');
var getContainer = function() { var getContainer = function() {
return container; return container;
@@ -1175,9 +1153,8 @@ describe('HtmlReporter', function() {
}); });
describe('and there are excluded specs', function() { describe('and there are excluded specs', function() {
var env, container, reporter, reporterConfig, specStatus; var container, reporter, reporterConfig, specStatus;
beforeEach(function() { beforeEach(function() {
env = new jasmineUnderTest.Env();
container = document.createElement('div'); container = document.createElement('div');
reporterConfig = { reporterConfig = {
env: env, env: env,
@@ -1239,9 +1216,8 @@ describe('HtmlReporter', function() {
}); });
describe('and there are pending specs', function() { describe('and there are pending specs', function() {
var env, container, reporter; var container, reporter;
beforeEach(function() { beforeEach(function() {
env = new jasmineUnderTest.Env();
container = document.createElement('div'); container = document.createElement('div');
var getContainer = function() { var getContainer = function() {
return container; return container;
@@ -1297,10 +1273,9 @@ describe('HtmlReporter', function() {
}); });
describe('and some tests fail', function() { describe('and some tests fail', function() {
var env, container, reporter; var container, reporter;
beforeEach(function() { beforeEach(function() {
env = new jasmineUnderTest.Env();
container = document.createElement('div'); container = document.createElement('div');
var getContainer = function() { var getContainer = function() {
return container; return container;
@@ -1469,8 +1444,7 @@ describe('HtmlReporter', function() {
describe('The overall result bar', function() { describe('The overall result bar', function() {
describe("When the jasmineDone event's overallStatus is 'passed'", function() { describe("When the jasmineDone event's overallStatus is 'passed'", function() {
it('has class jasmine-passed', function() { it('has class jasmine-passed', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -1500,8 +1474,7 @@ describe('HtmlReporter', function() {
describe("When the jasmineDone event's overallStatus is 'failed'", function() { describe("When the jasmineDone event's overallStatus is 'failed'", function() {
it('has class jasmine-failed', function() { it('has class jasmine-failed', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },
@@ -1531,8 +1504,7 @@ describe('HtmlReporter', function() {
describe("When the jasmineDone event's overallStatus is 'incomplete'", function() { describe("When the jasmineDone event's overallStatus is 'incomplete'", function() {
it('has class jasmine-incomplete', function() { it('has class jasmine-incomplete', function() {
var env = new jasmineUnderTest.Env(), var container = document.createElement('div'),
container = document.createElement('div'),
getContainer = function() { getContainer = function() {
return container; return container;
}, },

View File

@@ -19,6 +19,10 @@ describe('MatchersSpec - HTML Dependent', function() {
}); });
}); });
afterEach(function() {
env.cleanup_();
});
function match(value) { function match(value) {
return spec.expect(value); return spec.expect(value);
} }

View File

@@ -1188,6 +1188,12 @@ getJasmineRequireObj().Env = function(j$) {
throw new Error(message); throw new Error(message);
} }
}; };
this.cleanup_ = function() {
if (globalErrors) {
globalErrors.uninstall();
}
};
} }
return Env; return Env;