Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
fix: properly format err messages with new lines
Browse files Browse the repository at this point in the history
Fixes #40
  • Loading branch information
pkozlowski-opensource committed Aug 22, 2014
1 parent b4ee7f2 commit 1144690
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ var formatError = function(error) {
var message = error.message;

if (stack) {
var firstLine = stack.substring(0, stack.indexOf('\n'));
if (message && firstLine.indexOf(message) === -1) {
if (message && stack.indexOf(message) === -1) {
stack = message + '\n' + stack;
}

Expand Down
12 changes: 12 additions & 0 deletions test/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,16 @@ describe('adapter mocha', function() {
expect(createConfigObject(this.karma).globals).to.deep.eq(['__cov', 'test']);
});
});

describe('formatError', function () {

it('should properly format exceptions that contains \n in their message', function () {
var errLines = formatError(new Error('foo\nbar')).split('\n');
expect(errLines[0]).to.contain('foo');
expect(errLines[1]).to.equal('bar');
expect(errLines[2]).to.not.contain('foo');
expect(errLines[3]).to.not.contain('bar');
});

});
});

0 comments on commit 1144690

Please # to comment.