jest/prefer-snapshot-hint
eslint-plugin-jest
No autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-snapshot-hint": "error",
},
},
];const snapshotOutput = ({ stdout, stderr }) => {
expect(stdout).toMatchSnapshot();
expect(stderr).toMatchSnapshot();
};
describe('cli', () => {
describe('--version flag', () => {
it('prints the version', async () => {
snapshotOutput(await runCli(['--version']));
});
});
describe('--config flag', () => {
it('reads the config', async () => {
const { stdout, parsedConfig } = await runCli([
'--config',
'jest.config.js',
]);
expect(stdout).toMatchSnapshot();
expect(parsedConfig).toMatchSnapshot();
});
it('prints nothing to stderr', async () => {
const { stderr } = await runCli(['--config', 'jest.config.js']);
expect(stderr).toMatchSnapshot();
});
});
});const snapshotOutput = ({ stdout, stderr }, hints) => {
expect(stdout).toMatchSnapshot({}, `stdout: ${hints.stdout}`);
expect(stderr).toMatchSnapshot({}, `stderr: ${hints.stderr}`);
};
describe('cli', () => {
describe('--version flag', () => {
it('prints the version', async () => {
snapshotOutput(await runCli(['--version']), {
stdout: 'version string',
stderr: 'empty',
});
});
});
describe('--config flag', () => {
it('reads the config', async () => {
const { stdout } = await runCli(['--config', 'jest.config.js']);
expect(stdout).toMatchSnapshot({}, 'stdout: config settings');
});
it('prints nothing to stderr', async () => {
const { stderr } = await runCli(['--config', 'jest.config.js']);
expect(stderr).toMatchInlineSnapshot();
});
describe('when the file does not exist', () => {
it('throws an error', async () => {
await expect(
runCli(['--config', 'does-not-exist.js']),
// …const snapshotOutput = ({ stdout, stderr }, hints) => {
expect(stdout).toMatchSnapshot({}, `stdout: ${hints.stdout}`);
expect(stderr).toMatchSnapshot({}, `stderr: ${hints.stderr}`);
};
describe('cli', () => {
describe('--version flag', () => {
it('prints the version', async () => {
snapshotOutput(await runCli(['--version']), {
stdout: 'version string',
stderr: 'empty',
});
});
});
describe('--config flag', () => {
it('reads the config', async () => {
const { stdout } = await runCli(['--config', 'jest.config.js']);
expect(stdout).toMatchSnapshot();
});
it('prints nothing to stderr', async () => {
const { stderr } = await runCli(['--config', 'jest.config.js']);
expect(stderr).toMatchInlineSnapshot();
});
describe('when the file does not exist', () => {
it('throws an error', async () => {
await expect(
runCli(['--config', 'does-not-exist.js']),
// …Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
jest/prefer-snapshot-hint
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-snapshot-hint": "error",
},
},
];jest/prefer-snapshot-hint
jest plugin · correctness
{
"plugins": [
"jest"
],
"rules": {
"jest/prefer-snapshot-hint": "error"
}
}Biome does not have this rule.
Enforce including a hint with external snapshots
Prefer mock resolved/rejected shorthands for promises