Skip to content

Commit

Permalink
Add code comments documenting passing matcher results (#2253)
Browse files Browse the repository at this point in the history
* Add code comments documenting passing matcher results

* Fixed linting error
  • Loading branch information
ArtemGovorov authored and cpojer committed Dec 8, 2016
1 parent 8a0d760 commit 4ce6c30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/jest-matchers/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ const makeThrowingMatcher = (
if ((result.pass && isNot) || (!result.pass && !isNot)) { // XOR
const message = getMessage(result.message);
const error = new JestAssertionError(message);
// Passing the result of the matcher with the error so that a custom
// reporter could access the actual and expected objects of the result
// for example in order to display a custom visual diff
error.matcherResult = result;
// Remove this function from the stack trace frame.
Error.captureStackTrace(error, throwingMatcher);
Expand Down
6 changes: 6 additions & 0 deletions packages/jest-matchers/src/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ const matchers: MatchersObject = {
(diffString ? `\n\nDifference:\n\n${diffString}` : '');
};

// Passing the the actual and expected objects so that a custom reporter
// could access them, for example in order to display a custom visual diff,
// or create a different error message
return {actual: received, expected, message, name: 'toBe', pass};
},

Expand Down Expand Up @@ -396,6 +399,9 @@ const matchers: MatchersObject = {
(diffString ? `\n\nDifference:\n\n${diffString}` : '');
};

// Passing the the actual and expected objects so that a custom reporter
// could access them, for example in order to display a custom visual diff,
// or create a different error message
return {actual: received, expected, message, name: 'toEqual', pass};
},

Expand Down

0 comments on commit 4ce6c30

Please sign in to comment.