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

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