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:
@@ -3495,9 +3495,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 || {});
|
||||
|
||||
@@ -589,6 +589,32 @@ describe('Expectation', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('indents a multiline failure message', function() {
|
||||
var matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
return { pass: false, message: 'a\nmultiline\nmessage' };
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
}),
|
||||
actualMessage;
|
||||
|
||||
expectation.withContext('Some context').toFoo('hello');
|
||||
|
||||
actualMessage = addExpectationResult.calls.argsFor(0)[1].message;
|
||||
expect(actualMessage).toEqual(
|
||||
'Some context:\n a\n multiline\n message'
|
||||
);
|
||||
});
|
||||
|
||||
it('prepends the context to a custom failure message from a function', function() {
|
||||
var matchers = {
|
||||
toFoo: function() {
|
||||
|
||||
@@ -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 || {});
|
||||
|
||||
Reference in New Issue
Block a user