Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass toMatchSnapshot expected and actual for custom reporters #2342

Merged
merged 1 commit into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/jest-jasmine2/src/setup-jest-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const addSuppressedErrors = result => {

result.failedExpectations = suppressedErrors.map(error => ({
actual: '',
// passing error for custom test reporters
error,
expected: '',
message: error.message,
passed: false,
Expand Down
12 changes: 11 additions & 1 deletion packages/jest-snapshot/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,17 @@ const toMatchSnapshot = function(received: any, testName?: string) {
() => matcherHint('.toMatchSnapshot', 'value', '') + '\n\n' +
report();

return {message, pass: false, report};
// 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: actualString,
expected: expectedString,
message,
name: 'toMatchSnapshot',
pass: false,
report,
};
}
};

Expand Down