Detailed error messages in toThrow/toThrowError
- included what was thrown for failure messages in toThrow and toThrowError - fixed typo from 'execption' to 'exception' in toThrowError failure messages - clarified failure messages in toThrowError to include specific error types [Fixes #52680709]
This commit is contained in:
@@ -77,7 +77,7 @@ describe("toThrowError", function() {
|
||||
expect(result.message).toEqual("Expected function to throw an Error, but it threw undefined.");
|
||||
});
|
||||
|
||||
it("passes if thrown is an Error, but there is no expected error", function() {
|
||||
it("passes if thrown is a type of Error, but there is no expected error", function() {
|
||||
var matcher = j$.matchers.toThrowError(),
|
||||
fn = function() {
|
||||
throw new TypeError();
|
||||
@@ -100,7 +100,7 @@ describe("toThrowError", function() {
|
||||
result = matcher.compare(fn, "foo");
|
||||
|
||||
expect(result.pass).toBe(true);
|
||||
expect(result.message).toEqual("Expected function not to throw an execption with message 'foo'.");
|
||||
expect(result.message).toEqual("Expected function not to throw an exception with message 'foo'.");
|
||||
});
|
||||
|
||||
it("fails if thrown is an Error and the expected is not the same message", function() {
|
||||
@@ -113,7 +113,7 @@ describe("toThrowError", function() {
|
||||
result = matcher.compare(fn, "bar");
|
||||
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message).toEqual("Expected function to throw an execption with message 'bar'.");
|
||||
expect(result.message).toEqual("Expected function to throw an exception with message 'bar', but it threw an exception with message 'foo'.");
|
||||
});
|
||||
|
||||
it("passes if thrown is an Error and the expected is a RegExp that matches the message", function() {
|
||||
@@ -126,7 +126,7 @@ describe("toThrowError", function() {
|
||||
result = matcher.compare(fn, /long/);
|
||||
|
||||
expect(result.pass).toBe(true);
|
||||
expect(result.message).toEqual("Expected function not to throw an execption with a message matching /long/.");
|
||||
expect(result.message).toEqual("Expected function not to throw an exception with a message matching /long/.");
|
||||
});
|
||||
|
||||
it("fails if thrown is an Error and the expected is a RegExp that does not match the message", function() {
|
||||
@@ -139,7 +139,7 @@ describe("toThrowError", function() {
|
||||
result = matcher.compare(fn, /foo/);
|
||||
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message).toEqual("Expected function to throw an execption with a message matching /foo/.");
|
||||
expect(result.message).toEqual("Expected function to throw an exception with a message matching /foo/, but it threw an exception with message 'a long message'.");
|
||||
});
|
||||
|
||||
it("passes if thrown is an Error and the expected the same Error", function() {
|
||||
@@ -191,23 +191,23 @@ describe("toThrowError", function() {
|
||||
result = matcher.compare(fn, TypeError);
|
||||
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message).toEqual("Expected function to throw TypeError.");
|
||||
expect(result.message).toEqual("Expected function to throw TypeError, but it threw Error.");
|
||||
});
|
||||
|
||||
it("passes if thrown is an Error and it is equal to the expected Error and message", function() {
|
||||
it("passes if thrown is a type of Error and it is equal to the expected Error and message", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').andReturn(true)
|
||||
},
|
||||
matcher = j$.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new Error("foo");
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
result;
|
||||
|
||||
result = matcher.compare(fn, Error, "foo");
|
||||
result = matcher.compare(fn, TypeError, "foo");
|
||||
|
||||
expect(result.pass).toBe(true);
|
||||
expect(result.message).toEqual("Expected function not to throw Error with message \"foo\".");
|
||||
expect(result.message).toEqual("Expected function not to throw TypeError with message \"foo\".");
|
||||
});
|
||||
|
||||
it("passes if thrown is a custom error that takes arguments and it is equal to the expected custom error and message", function() {
|
||||
@@ -227,54 +227,54 @@ describe("toThrowError", function() {
|
||||
result = matcher.compare(fn, CustomError, "foo");
|
||||
|
||||
expect(result.pass).toBe(true);
|
||||
expect(result.message).toEqual("Expected function not to throw Error with message \"foo\".");
|
||||
expect(result.message).toEqual("Expected function not to throw CustomError with message \"foo\".");
|
||||
});
|
||||
|
||||
it("fails if thrown is an Error and the expected is a different Error", function() {
|
||||
it("fails if thrown is a type of Error and the expected is a different Error", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').andReturn(false)
|
||||
},
|
||||
matcher = j$.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new Error("foo");
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
result;
|
||||
|
||||
result = matcher.compare(fn, Error, "bar");
|
||||
result = matcher.compare(fn, TypeError, "bar");
|
||||
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message).toEqual("Expected function to throw Error with message \"bar\".");
|
||||
expect(result.message).toEqual("Expected function to throw TypeError with message \"bar\", but it threw TypeError with message \"foo\".");
|
||||
});
|
||||
|
||||
it("passes if thrown is an Error and has the same type as the expected Error and the message matches the exepcted message", function() {
|
||||
it("passes if thrown is a type of Error and has the same type as the expected Error and the message matches the exepcted message", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').andReturn(true)
|
||||
},
|
||||
matcher = j$.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new Error("foo");
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
result;
|
||||
|
||||
result = matcher.compare(fn, Error, /foo/);
|
||||
result = matcher.compare(fn, TypeError, /foo/);
|
||||
|
||||
expect(result.pass).toBe(true);
|
||||
expect(result.message).toEqual("Expected function not to throw Error with message matching /foo/.");
|
||||
expect(result.message).toEqual("Expected function not to throw TypeError with message matching /foo/.");
|
||||
});
|
||||
|
||||
it("fails if thrown is an Error and the expected is a different Error", function() {
|
||||
it("fails if thrown is a type of Error and the expected is a different Error", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').andReturn(false)
|
||||
},
|
||||
matcher = j$.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new Error("foo");
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
result;
|
||||
|
||||
result = matcher.compare(fn, Error, /bar/);
|
||||
result = matcher.compare(fn, TypeError, /bar/);
|
||||
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message).toEqual("Expected function to throw Error with message matching /bar/.");
|
||||
expect(result.message).toEqual("Expected function to throw TypeError with message matching /bar/, but it threw TypeError with message \"foo\".");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user