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:
Sheel Choksi
2013-07-12 23:21:10 -07:00
parent 5b986c953c
commit c91df21a96
5 changed files with 57 additions and 49 deletions

View File

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

View File

@@ -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) + ".");
}
}