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:
Sheel Choksi
2014-02-18 19:58:07 -08:00
parent 46d2c43da1
commit 76ca5ef6d4
11 changed files with 142 additions and 98 deletions

View File

@@ -43,7 +43,11 @@ getJasmineRequireObj().Expectation = function() {
args.unshift(name);
message = this.util.buildFailureMessage.apply(null, args);
} else {
message = result.message;
if (Object.prototype.toString.apply(result.message) === "[object Function]") {
message = result.message();
} else {
message = result.message;
}
}
}