diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 32363b08..b7f22d54 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2073,7 +2073,7 @@ getJasmineRequireObj().toThrow = function(j$) { if (arguments.length == 1) { result.pass = true; - result.message = "Expected function not to throw."; + result.message = "Expected function not to throw, but it threw " + j$.pp(thrown) + "."; return result; } @@ -2082,7 +2082,7 @@ getJasmineRequireObj().toThrow = function(j$) { result.pass = true; result.message = "Expected function not to throw " + j$.pp(expected) + "."; } else { - result.message = "Expected function to throw " + j$.pp(expected) + "."; + result.message = "Expected function to throw " + j$.pp(expected) + ", but it threw " + j$.pp(thrown) + "."; } return result; @@ -2130,17 +2130,19 @@ getJasmineRequireObj().toThrowError = function(j$) { if (errorType && message) { if (thrown.constructor == errorType && util.equals(thrown.message, message)) { - return pass("Expected function not to throw Error with message \"" + message + "\"."); + return pass("Expected function not to throw " + errorType.name + " with message \"" + message + "\"."); } else { - return fail("Expected function to throw Error with message \"" + message + "\"."); + return fail("Expected function to throw " + errorType.name + " with message \"" + message + + "\", but it threw " + thrown.constructor.name + " with message \"" + thrown.message + "\"."); } } if (errorType && regexp) { if (thrown.constructor == errorType && regexp.test(thrown.message)) { - return pass("Expected function not to throw Error with message matching " + regexp + "."); + return pass("Expected function not to throw " + errorType.name + " with message matching " + regexp + "."); } else { - return fail("Expected function to throw Error with message matching " + regexp + "."); + return fail("Expected function to throw " + errorType.name + " with message matching " + regexp + + ", but it threw " + thrown.constructor.name + " with message \"" + thrown.message + "\"."); } } @@ -2148,23 +2150,25 @@ getJasmineRequireObj().toThrowError = function(j$) { if (thrown.constructor == errorType) { return pass("Expected function not to throw " + errorType.name + "."); } else { - return fail("Expected function to throw " + errorType.name + "."); + return fail("Expected function to throw " + errorType.name + ", but it threw " + thrown.constructor.name + "."); } } if (message) { if (thrown.message == message) { - return pass("Expected function not to throw an execption with message " + j$.pp(message) + "."); + return pass("Expected function not to throw an exception with message " + j$.pp(message) + "."); } else { - return fail("Expected function to throw an execption with message " + j$.pp(message) + "."); + return fail("Expected function to throw an exception with message " + j$.pp(message) + + ", but it threw an exception with message " + j$.pp(thrown.message) + "."); } } if (regexp) { if (regexp.test(thrown.message)) { - return pass("Expected function not to throw an execption with a message matching " + j$.pp(regexp) + "."); + return pass("Expected function not to throw an exception with a message matching " + j$.pp(regexp) + "."); } else { - return fail("Expected function to throw an execption with a message matching " + j$.pp(regexp) + "."); + return fail("Expected function to throw an exception with a message matching " + j$.pp(regexp) + + ", but it threw an exception with message " + j$.pp(thrown.message) + "."); } } diff --git a/spec/core/matchers/toThrowErrorSpec.js b/spec/core/matchers/toThrowErrorSpec.js index 2b26bae0..3c65d8c9 100644 --- a/spec/core/matchers/toThrowErrorSpec.js +++ b/spec/core/matchers/toThrowErrorSpec.js @@ -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\"."); }); }); diff --git a/spec/core/matchers/toThrowSpec.js b/spec/core/matchers/toThrowSpec.js index 7ba205c3..ee2c5708 100644 --- a/spec/core/matchers/toThrowSpec.js +++ b/spec/core/matchers/toThrowSpec.js @@ -33,7 +33,7 @@ describe("toThrow", function() { result = matcher.compare(fn); expect(result.pass).toBe(true); - expect(result.message).toEqual("Expected function not to throw."); + expect(result.message).toEqual("Expected function not to throw, but it threw 5."); }); it("passes even if what is thrown is falsy", function() { @@ -45,7 +45,7 @@ describe("toThrow", function() { result = matcher.compare(fn); expect(result.pass).toBe(true); - expect(result.message).toEqual("Expected function not to throw."); + expect(result.message).toEqual("Expected function not to throw, but it threw undefined."); }); it("passes if what is thrown is equivalent to what is expected", function() { @@ -77,7 +77,7 @@ describe("toThrow", function() { result = matcher.compare(fn, "foo"); expect(result.pass).toBe(false); - expect(result.message).toEqual("Expected function to throw 'foo'."); + expect(result.message).toEqual("Expected function to throw 'foo', but it threw 5."); }); it("fails if what is thrown is not equivalent to undefined", function() { @@ -93,6 +93,6 @@ describe("toThrow", function() { result = matcher.compare(fn, void 0); expect(result.pass).toBe(false); - expect(result.message).toEqual("Expected function to throw undefined."); + expect(result.message).toEqual("Expected function to throw undefined, but it threw 5."); }); }); \ No newline at end of file diff --git a/src/core/matchers/toThrow.js b/src/core/matchers/toThrow.js index 1079148c..4a2fa1dd 100644 --- a/src/core/matchers/toThrow.js +++ b/src/core/matchers/toThrow.js @@ -25,7 +25,7 @@ getJasmineRequireObj().toThrow = function(j$) { if (arguments.length == 1) { result.pass = true; - result.message = "Expected function not to throw."; + result.message = "Expected function not to throw, but it threw " + j$.pp(thrown) + "."; return result; } @@ -34,7 +34,7 @@ getJasmineRequireObj().toThrow = function(j$) { result.pass = true; result.message = "Expected function not to throw " + j$.pp(expected) + "."; } else { - result.message = "Expected function to throw " + j$.pp(expected) + "."; + result.message = "Expected function to throw " + j$.pp(expected) + ", but it threw " + j$.pp(thrown) + "."; } return result; diff --git a/src/core/matchers/toThrowError.js b/src/core/matchers/toThrowError.js index 0fe1e125..6354795f 100644 --- a/src/core/matchers/toThrowError.js +++ b/src/core/matchers/toThrowError.js @@ -35,17 +35,19 @@ getJasmineRequireObj().toThrowError = function(j$) { if (errorType && message) { if (thrown.constructor == errorType && util.equals(thrown.message, message)) { - return pass("Expected function not to throw Error with message \"" + message + "\"."); + return pass("Expected function not to throw " + errorType.name + " with message \"" + message + "\"."); } else { - return fail("Expected function to throw Error with message \"" + message + "\"."); + return fail("Expected function to throw " + errorType.name + " with message \"" + message + + "\", but it threw " + thrown.constructor.name + " with message \"" + thrown.message + "\"."); } } if (errorType && regexp) { if (thrown.constructor == errorType && regexp.test(thrown.message)) { - return pass("Expected function not to throw Error with message matching " + regexp + "."); + return pass("Expected function not to throw " + errorType.name + " with message matching " + regexp + "."); } else { - return fail("Expected function to throw Error with message matching " + regexp + "."); + return fail("Expected function to throw " + errorType.name + " with message matching " + regexp + + ", but it threw " + thrown.constructor.name + " with message \"" + thrown.message + "\"."); } } @@ -53,23 +55,25 @@ getJasmineRequireObj().toThrowError = function(j$) { if (thrown.constructor == errorType) { return pass("Expected function not to throw " + errorType.name + "."); } else { - return fail("Expected function to throw " + errorType.name + "."); + return fail("Expected function to throw " + errorType.name + ", but it threw " + thrown.constructor.name + "."); } } if (message) { if (thrown.message == message) { - return pass("Expected function not to throw an execption with message " + j$.pp(message) + "."); + return pass("Expected function not to throw an exception with message " + j$.pp(message) + "."); } else { - return fail("Expected function to throw an execption with message " + j$.pp(message) + "."); + return fail("Expected function to throw an exception with message " + j$.pp(message) + + ", but it threw an exception with message " + j$.pp(thrown.message) + "."); } } if (regexp) { if (regexp.test(thrown.message)) { - return pass("Expected function not to throw an execption with a message matching " + j$.pp(regexp) + "."); + return pass("Expected function not to throw an exception with a message matching " + j$.pp(regexp) + "."); } else { - return fail("Expected function to throw an execption with a message matching " + j$.pp(regexp) + "."); + return fail("Expected function to throw an exception with a message matching " + j$.pp(regexp) + + ", but it threw an exception with message " + j$.pp(thrown.message) + "."); } }