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 all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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]` [**BREAKING**] Remove `report` method and throw matcher errors ([#9049](https://github.com/facebook/jest/pull/9049))
- `[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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 matchers cannot be used with not');
expect(exitCode).toBe(1);
}
});
Expand Down
6 changes: 4 additions & 2 deletions e2e/__tests__/toThrowErrorMatchingSnapshot.test.ts
Original file line number Diff line number Diff line change
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 matchers cannot be used with not');
expect(exitCode).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 @@ -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 matchers cannot be used with not'
);
});

Expand Down
7 changes: 5 additions & 2 deletions packages/jest-matcher-utils/src/index.ts
Original file line number Diff line number Diff line change
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.

Loading