Skip to content

Commit

Permalink
Amend jest snapshot to tie in nicely with Ava (#2130)
Browse files Browse the repository at this point in the history
  • Loading branch information
lithin authored and cpojer committed Nov 29, 2016
1 parent d3dbf46 commit 7a36a0d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/jest-snapshot/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const initializeSnapshotState = (
const getSnapshotState = () => snapshotState;

const toMatchSnapshot = function(received: any, expected: void) {
this.dontThrow();
this.dontThrow && this.dontThrow();

const {currentTestName, isNot, snapshotState} = this;

Expand All @@ -87,7 +87,6 @@ const toMatchSnapshot = function(received: any, expected: void) {
} else {
const {count, expected, actual} = result;


const expectedString = expected.trim();
const actualString = actual.trim();
const diffMessage = diff(
Expand All @@ -100,21 +99,24 @@ const toMatchSnapshot = function(received: any, expected: void) {
},
);

const message =
() => matcherHint('.toMatchSnapshot', 'value', '') + '\n\n' +
`${RECEIVED_COLOR('Received value')} does not match ` +
const report =
() => `${RECEIVED_COLOR('Received value')} does not match ` +
`${EXPECTED_COLOR('stored snapshot ' + count)}.\n\n` +
(diffMessage || (
RECEIVED_COLOR('- ' + expectedString) + '\n' +
EXPECTED_COLOR('+ ' + actualString)
));

return {message, pass: false};
const message =
() => matcherHint('.toMatchSnapshot', 'value', '') + '\n\n' +
report();

return {message, pass: false, report};
}
};

const toThrowErrorMatchingSnapshot = function(received: any, expected: void) {
this.dontThrow();
this.dontThrow && this.dontThrow();
const {isNot} = this;

if (isNot) {
Expand Down

0 comments on commit 7a36a0d

Please sign in to comment.