Indent multiline failure messages in the output of withContext

This makes it easier to see where each failure message begins and ends.

Before:
   Some context: a
   multiline
   message

After:
   Some context:
       a
       multiline
       message
This commit is contained in:
Steve Gravrock
2019-09-28 12:31:00 -07:00
parent a497d0942a
commit 10dbf8be98
3 changed files with 48 additions and 2 deletions

View File

@@ -176,9 +176,19 @@ getJasmineRequireObj().Expectation = function(j$) {
}
ContextAddingFilter.prototype.modifyFailureMessage = function(msg) {
return this.message + ': ' + msg;
var nl = msg.indexOf('\n');
if (nl === -1) {
return this.message + ': ' + msg;
} else {
return this.message + ':\n' + indent(msg);
}
};
function indent(s) {
return s.replace(/^/gm, ' ');
}
return {
factory: function(options) {
return new Expectation(options || {});