Skip to content

Commit

Permalink
Merge 82c4371 into 2a00362
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jan 9, 2015
2 parents 2a00362 + 82c4371 commit 6ffd784
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,12 @@ module.exports = function (expect) {
});

expect.addAssertion('function', 'when called with', function (expect, subject, args) { // ...
this.errorMode = 'nested';
this.shift(expect, subject.apply(subject, args), 1);
});

expect.addAssertion('array', 'when passed as parameters to', function (expect, subject, fn) { // ...
this.errorMode = 'nested';
this.shift(expect, fn.apply(fn, subject), 1);
});
};
24 changes: 19 additions & 5 deletions test/unexpected.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3753,16 +3753,18 @@ describe('unexpected', function () {
'function add(a, b) {\n' +
' return a + b;\n' +
'}\n' +
'when called with [ 3, 4 ] to equal 9');
'when called with [ 3, 4 ] to equal 9\n' +
' expected 7 to equal 9');

expect(function () {
expect(add, 'when called with', [3, 4], 'to satisfy', 'to equal', 9);
}, 'to throw',
'expected\n' +
'function add(a, b) {\n' +
' return a + b;\n' +
'}\n' +
"when called with [ 3, 4 ] to satisfy 'to equal', 9"); // DAMN, fix me
'function add(a, b) {\n' +
' return a + b;\n' +
'}\n' +
"when called with [ 3, 4 ] to satisfy 'to equal', 9\n" + // DAMN, fix me
" expected 7 to satisfy 'to equal', 9"); // DAMN, fix me
});
});

Expand All @@ -3771,6 +3773,18 @@ describe('unexpected', function () {
expect([3, 4], 'when passed as parameters to', add, 'to equal', 7);
});

it('should produce a nested error message when the assertion fails', function () {
expect(function () {
expect([3, 4], 'when passed as parameters to', add, 'to equal', 8);
}, 'to throw',
'expected [ 3, 4 ] when passed as parameters to\n' +
'function add(a, b) {\n' +
' return a + b;\n' +
'} to equal 8\n' +
' expected 7 to equal 8');

});

it('should combine with other assertions (showcase)', function () {
expect([[1, 2], [3, 4]], 'to be an array whose items satisfy', 'when passed as parameters to', add, 'to be a number');
});
Expand Down

0 comments on commit 6ffd784

Please sign in to comment.