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

#6003: include snapshot name in error message #6015

Merged
merged 6 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Features

* `[jest-snapshot]` [**BREAKING**] Concatenate name of test, optional snapshot name and count
([#6015](https://github.com/facebook/jest/pull/6015))
* `[jest-runtime]` Allow for transform plugins to skip the definition process
method if createTransformer method was defined.
([#5999](https://github.com/facebook/jest/pull/5999))
Expand Down
26 changes: 26 additions & 0 deletions integration-tests/__tests__/__snapshots__/failures.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,32 @@ exports[`works with async failures 1`] = `
"
`;

exports[`works with named snapshot failures 1`] = `
"FAIL __tests__/snapshot_named.test.js
✕ failing named snapshot

● failing named snapshot

expect(value).toMatchSnapshot()

Received value does not match stored snapshot snapname 1.

- \\"bar\\"
+ \\"foo\\"

10 |
11 | test('failing named snapshot', () => {
> 12 | expect('foo').toMatchSnapshot('snapname');
| ^
13 | });
14 |

at __tests__/snapshot_named.test.js:12:17

› 1 snapshot test failed.
"
`;

exports[`works with node assert 1`] = `
"FAIL __tests__/node_assertion_error.test.js
✕ assert
Expand Down
10 changes: 10 additions & 0 deletions integration-tests/__tests__/failures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,13 @@ test('works with snapshot failures', () => {
result.substring(0, result.indexOf('Snapshot Summary')),
).toMatchSnapshot();
});

test('works with named snapshot failures', () => {
const {stderr} = runJest(dir, ['snapshot_named.test.js']);

const result = normalizeDots(extractSummary(stderr).rest);

expect(
result.substring(0, result.indexOf('Snapshot Summary')),
).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`failing named snapshot: snapname 1`] = `"bar"`;
13 changes: 13 additions & 0 deletions integration-tests/failures/__tests__/snapshot_named.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+jsinfra
*/
'use strict';

test('failing named snapshot', () => {
expect('foo').toMatchSnapshot('snapname');
});
4 changes: 3 additions & 1 deletion packages/jest-snapshot/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ const toMatchSnapshot = function(received: any, testName?: string) {

report = () =>
`${RECEIVED_COLOR('Received value')} does not match ` +
`${EXPECTED_COLOR('stored snapshot ' + count)}.\n\n` +
`${EXPECTED_COLOR(
`stored snapshot ${testName ? testName + ' ' : ''}${count}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`stored snapshot "${testName ? testName + ' ' : ''}${count}"`,

perhaps? (wrapping in double quotes)

)}.\n\n` +
(diffMessage ||
EXPECTED_COLOR('- ' + (expected || '')) +
'\n' +
Expand Down