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

@@ -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() {