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: Remove report method and throw matcher errors #9049

Merged
merged 7 commits into from Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -37,6 +37,7 @@
- `[jest-snapshot]` Remove only the added newlines in multiline snapshots ([#8859](https://github.com/facebook/jest/pull/8859))
- `[jest-snapshot]` Distinguish empty string from external snapshot not written ([#8880](https://github.com/facebook/jest/pull/8880))
- `[jest-snapshot]` [**BREAKING**] Distinguish empty string from internal snapshot not written ([#8898](https://github.com/facebook/jest/pull/8898))
- `[jest-snapshot]` Remove `report` method and throw matcher errors ([#9049](https://github.com/facebook/jest/pull/9049))
pedrottimark marked this conversation as resolved.
Show resolved Hide resolved
- `[jest-transform]` Properly cache transformed files across tests ([#8890](https://github.com/facebook/jest/pull/8890))

### Chore & Maintenance
Expand Down
10 changes: 5 additions & 5 deletions e2e/__tests__/toMatchSnapshot.test.ts
Expand Up @@ -196,7 +196,7 @@ test('handles invalid property matchers', () => {
`,
});
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch('Property matchers must be an object.');
expect(stderr).toMatch('Expected properties must be an object');
expect(exitCode).toBe(1);
}
{
Expand All @@ -207,9 +207,9 @@ test('handles invalid property matchers', () => {
`,
});
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch('Property matchers must be an object.');
expect(stderr).toMatch('Expected properties must be an object');
expect(stderr).toMatch(
'To provide a snapshot test name without property matchers, use: toMatchSnapshot("name")',
`To provide a hint without properties: toMatchSnapshot('hint')`,
);
expect(exitCode).toBe(1);
}
Expand All @@ -221,9 +221,9 @@ test('handles invalid property matchers', () => {
`,
});
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch('Property matchers must be an object.');
expect(stderr).toMatch('Expected properties must be an object');
expect(stderr).toMatch(
'To provide a snapshot test name without property matchers, use: toMatchSnapshot("name")',
`To provide a hint without properties: toMatchSnapshot('hint')`,
);
expect(exitCode).toBe(1);
}
Expand Down
6 changes: 4 additions & 2 deletions e2e/__tests__/toThrowErrorMatchingInlineSnapshot.test.ts
Expand Up @@ -74,14 +74,16 @@ test('cannot be used with .not', () => {
const filename = 'cannot-be-used-with-not.test.js';
const template = makeTemplate(`
test('cannot be used with .not', () => {
expect('').not.toThrowErrorMatchingInlineSnapshot();
expect(() => { throw new Error('apple'); })
.not
.toThrowErrorMatchingInlineSnapshot();
});
`);

{
writeFiles(TESTS_DIR, {[filename]: template()});
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch('.not cannot be used with snapshot matchers');
expect(stderr).toMatch('Snapshot assertion must not have not');
pedrottimark marked this conversation as resolved.
Show resolved Hide resolved
expect(exitCode).toBe(1);
}
});
Expand Down
6 changes: 4 additions & 2 deletions e2e/__tests__/toThrowErrorMatchingSnapshot.test.ts
Expand Up @@ -67,14 +67,16 @@ test('accepts custom snapshot name', () => {
test('cannot be used with .not', () => {
const filename = 'cannot-be-used-with-not.test.js';
const template = makeTemplate(`test('cannot be used with .not', () => {
expect('').not.toThrowErrorMatchingSnapshot();
expect(() => { throw new Error('apple'); })
.not
.toThrowErrorMatchingSnapshot();
});
`);

{
writeFiles(TESTS_DIR, {[filename]: template()});
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]);
expect(stderr).toMatch('.not cannot be used with snapshot matchers');
expect(stderr).toMatch('Snapshot assertion must not have not');
expect(exitCode).toBe(1);
}
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/snapshot/__tests__/snapshot.test.js
Expand Up @@ -30,7 +30,7 @@ describe('snapshot', () => {

it('cannot be used with .not', () => {
expect(() => expect('').not.toMatchSnapshot()).toThrow(
'.not cannot be used with snapshot matchers'
'Snapshot assertion must not have not'
);
});

Expand Down
7 changes: 5 additions & 2 deletions packages/jest-matcher-utils/src/index.ts
Expand Up @@ -415,8 +415,11 @@ export const getLabelPrinter = (...strings: Array<string>): PrintLabel => {
export const matcherErrorMessage = (
hint: string, // assertion returned from call to matcherHint
generic: string, // condition which correct value must fulfill
specific: string, // incorrect value returned from call to printWithType
) => `${hint}\n\n${chalk.bold('Matcher error')}: ${generic}\n\n${specific}`;
specific?: string, // incorrect value returned from call to printWithType
) =>
`${hint}\n\n${chalk.bold('Matcher error')}: ${generic}${
typeof specific === 'string' ? '\n\n' + specific : ''
}`;

// Display assertion for the report when a test fails.
// New format: rejects/resolves, not, and matcher name have black color
Expand Down

This file was deleted.