vitest/prefer-snapshot-hint
@vitest/eslint-plugin
No autofix
eslint.config.js
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/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',
'vitest.config.js',
])
expect(stdout).toMatchSnapshot()
expect(parsedConfig).toMatchSnapshot()
})
it('prints nothing to stderr', async () => {
const { stderr } = await runCli(['--config', 'vitest.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', 'vitest.config.js'])
expect(stdout).toMatchSnapshot({}, 'stdout: config settings')
})
it('prints nothing to stderr', async () => {
const { stderr } = await runCli(['--config', 'vitest.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', 'vitest.config.js'])
expect(stdout).toMatchSnapshot()
})
it('prints nothing to stderr', async () => {
const { stderr } = await runCli(['--config', 'vitest.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.
vitest/prefer-snapshot-hint
@vitest/eslint-plugin
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-snapshot-hint": "error",
},
},
];vitest/prefer-snapshot-hint
vitest plugin · correctness
{
"plugins": [
"vitest"
],
"rules": {
"vitest/prefer-snapshot-hint": "error"
}
}Biome does not have this rule.
Prefer including a hint with external snapshots
Enforce using toBe(true) and toBe(false) over matchers that coerce types to boolean
Enforce mock resolved/rejected shorthands for promises