Allow matcher custom failure messages to be a function
By deferring the evaluation of these messages, we can avoid the
expensive creation of them when in the majority use case (tests are
passing) they are not needed.
These failure messages were causing performance problems with larger
objects needed to be pretty printed as discussed in #520 and brought up
by @rdy.
[fixes #65925900][fixes #520]
This commit is contained in:
@@ -25,16 +25,16 @@ getJasmineRequireObj().toThrow = function(j$) {
|
||||
|
||||
if (arguments.length == 1) {
|
||||
result.pass = true;
|
||||
result.message = "Expected function not to throw, but it threw " + j$.pp(thrown) + ".";
|
||||
result.message = function() { return "Expected function not to throw, but it threw " + j$.pp(thrown) + "."; };
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (util.equals(thrown, expected)) {
|
||||
result.pass = true;
|
||||
result.message = "Expected function not to throw " + j$.pp(expected) + ".";
|
||||
result.message = function() { return "Expected function not to throw " + j$.pp(expected) + "."; };
|
||||
} else {
|
||||
result.message = "Expected function to throw " + j$.pp(expected) + ", but it threw " + j$.pp(thrown) + ".";
|
||||
result.message = function() { return "Expected function to throw " + j$.pp(expected) + ", but it threw " + j$.pp(thrown) + "."; };
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user