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

@@ -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));

View File

@@ -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();

View File

@@ -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);

View File

@@ -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();

View File

@@ -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');