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

jest-snapshot: Improve report when matcher fails, part 14 #8132

Merged
merged 13 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Features

- `[jest-snapshot]` Improve report when matcher fails, part 14 ([#8132](https://github.com/facebook/jest/pull/8132))

### Fixes

### Chore & Maintenance
Expand Down
8 changes: 4 additions & 4 deletions e2e/__tests__/__snapshots__/failures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ FAIL __tests__/snapshotNamed.test.js

● failing named snapshot

expect(value).toMatchSnapshot()
expect(received).toMatchSnapshot(name)

Received value does not match stored snapshot "failing named snapshot: snapname 1".
Snapshot key: \`failing named snapshot: snapname 1\`
pedrottimark marked this conversation as resolved.
Show resolved Hide resolved

- Snapshot
+ Received
Expand Down Expand Up @@ -819,9 +819,9 @@ FAIL __tests__/snapshot.test.js

● failing snapshot

expect(value).toMatchSnapshot()
expect(received).toMatchSnapshot()

Received value does not match stored snapshot "failing snapshot 1".
Snapshot key: \`failing snapshot 1\`

- Snapshot
+ Received
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ exports[`can press "u" to update snapshots: test results 1`] = `
FAIL __tests__/bar.spec.js
✕ bar
● bar
expect(value).toMatchSnapshot()
Received value does not match stored snapshot "bar 1".
expect(received).toMatchSnapshot()
Snapshot key: \`bar 1\`
- Snapshot
+ Received
- "foo"
Expand Down
6 changes: 2 additions & 4 deletions e2e/__tests__/toMatchInlineSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('basic support', () => {
});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
const fileAfter = readFile(filename);
expect(stderr).toMatch('Received value does not match stored snapshot');
expect(stderr).toMatch('Snapshot key: `inline snapshots 1`');
expect(status).toBe(1);
expect(wrap(fileAfter)).toMatchSnapshot('snapshot mismatch');
}
Expand Down Expand Up @@ -101,9 +101,7 @@ test('handles property matchers', () => {
});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
const fileAfter = readFile(filename);
expect(stderr).toMatch(
'Received value does not match snapshot properties for "handles property matchers 1".',
);
expect(stderr).toMatch('Snapshot key: `handles property matchers 1`');
expect(stderr).toMatch('Snapshots: 1 failed, 1 total');
expect(status).toBe(1);
expect(wrap(fileAfter)).toMatchSnapshot('snapshot failed');
Expand Down
18 changes: 8 additions & 10 deletions e2e/__tests__/toMatchSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test('basic support', () => {
[filename]: template(['{apple: "updated value"}']),
});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch('Received value does not match stored snapshot');
expect(stderr).toMatch('Snapshot key: `snapshots 1`');
expect(status).toBe(1);
}

Expand Down Expand Up @@ -107,7 +107,7 @@ test('first snapshot fails, second passes', () => {
{
writeFiles(TESTS_DIR, {[filename]: template([`'kiwi'`, `'banana'`])});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch('Received value does not match stored snapshot');
expect(stderr).toMatch('Snapshot key: `snapshots 1`');
expect(stderr).toMatch('- "apple"\n + "kiwi"');
expect(stderr).not.toMatch('1 obsolete snapshot found');
expect(status).toBe(1);
Expand Down Expand Up @@ -178,9 +178,7 @@ test('handles property matchers', () => {
{
writeFiles(TESTS_DIR, {[filename]: template(['"string"'])});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch(
'Received value does not match snapshot properties for "handles property matchers 1".',
);
expect(stderr).toMatch('Snapshot key: `handles property matchers 1`');
expect(stderr).toMatch('Snapshots: 1 failed, 1 total');
expect(status).toBe(1);
}
Expand Down Expand Up @@ -253,9 +251,9 @@ test('handles property matchers with custom name', () => {
writeFiles(TESTS_DIR, {[filename]: template(['"string"'])});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch(
'Received value does not match snapshot properties for "handles property matchers with name: custom-name 1".',
'Snapshot key: `handles property matchers with name: custom-name 1`',
);
expect(stderr).toMatch('Expected snapshot to match properties:');
expect(stderr).toMatch('Expected properties:');
expect(stderr).toMatch('Snapshots: 1 failed, 1 total');
expect(status).toBe(1);
}
Expand Down Expand Up @@ -285,9 +283,9 @@ test('handles property matchers with deep properties', () => {
writeFiles(TESTS_DIR, {[filename]: template(['"string"', '"Jest"'])});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch(
'Received value does not match snapshot properties for "handles property matchers with deep properties 1".',
'Snapshot key: `handles property matchers with deep properties 1`',
);
expect(stderr).toMatch('Expected snapshot to match properties:');
expect(stderr).toMatch('Expected properties:');
expect(stderr).toMatch('Snapshots: 1 failed, 1 total');
expect(status).toBe(1);
}
Expand All @@ -296,7 +294,7 @@ test('handles property matchers with deep properties', () => {
writeFiles(TESTS_DIR, {[filename]: template(['new Date()', '"CHANGED"'])});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch(
'Received value does not match stored snapshot "handles property matchers with deep properties 1"',
'Snapshot key: `handles property matchers with deep properties 1`',
);
expect(stderr).toMatch('Snapshots: 1 failed, 1 total');
expect(status).toBe(1);
Expand Down
4 changes: 1 addition & 3 deletions e2e/__tests__/toThrowErrorMatchingInlineSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ test('cannot be used with .not', () => {
{
writeFiles(TESTS_DIR, {[filename]: template()});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch(
'Jest: `.not` cannot be used with `.toThrowErrorMatchingInlineSnapshot()`.',
);
expect(stderr).toMatch('.not cannot be used with snapshot matchers');
expect(status).toBe(1);
}
});
Expand Down
6 changes: 2 additions & 4 deletions e2e/__tests__/toThrowErrorMatchingSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test(`throws the error if tested function didn't throw error`, () => {
{
writeFiles(TESTS_DIR, {[filename]: template()});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch(`Expected the function to throw an error.`);
expect(stderr).toMatch('Received function did not throw');
expect(status).toBe(1);
}
});
Expand Down Expand Up @@ -74,9 +74,7 @@ test('cannot be used with .not', () => {
{
writeFiles(TESTS_DIR, {[filename]: template()});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch(
'Jest: `.not` cannot be used with `.toThrowErrorMatchingSnapshot()`.',
);
expect(stderr).toMatch('.not cannot be used with snapshot matchers');
expect(status).toBe(1);
}
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/snapshot/__tests__/snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('snapshot', () => {

it('cannot be used with .not', () => {
expect(() => expect('').not.toMatchSnapshot()).toThrow(
'Jest: `.not` cannot be used with `.toMatchSnapshot()`.'
'.not cannot be used with snapshot matchers'
);
});

Expand Down
Loading