From d91846f2bedcf81c20d0219c78b86d177471c30b Mon Sep 17 00:00:00 2001 From: Artem Govorov Date: Fri, 16 Dec 2016 12:06:06 +1000 Subject: [PATCH] Pass `toMatchSnapshot` `expected` and `actual` for custom reporters --- packages/jest-jasmine2/src/setup-jest-globals.js | 2 ++ packages/jest-snapshot/src/index.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/jest-jasmine2/src/setup-jest-globals.js b/packages/jest-jasmine2/src/setup-jest-globals.js index 27d71d9c86be..8affc557634e 100644 --- a/packages/jest-jasmine2/src/setup-jest-globals.js +++ b/packages/jest-jasmine2/src/setup-jest-globals.js @@ -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, diff --git a/packages/jest-snapshot/src/index.js b/packages/jest-snapshot/src/index.js index 1c3b5df36fa5..a6f6d18f1652 100644 --- a/packages/jest-snapshot/src/index.js +++ b/packages/jest-snapshot/src/index.js @@ -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, + }; } };