# prefer-snapshot-hint

Rule `jest/prefer-snapshot-hint`. Prefer including a hint with external snapshots

- Source: jest
- Technologies: Testing
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1761 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/prefer-snapshot-hint` | no | no | package `eslint-plugin-jest` | [docs](https://github.com/jest-community/eslint-plugin-jest/blob/v29.17.2/docs/rules/prefer-snapshot-hint.md) |
| Oxlint | `jest/prefer-snapshot-hint` | no | no | plugin `jest`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-snapshot-hint.html) |

## Code examples

### Incorrect: the rule reports this

```js
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();
    });
  });
});
```

### Correct: the rule accepts this

```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({}, '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']),
// …
```

```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.

## Enable it

### ESLint: `eslint.config.js`

```js
import jest from "eslint-plugin-jest";

export default [
  {
    plugins: { jest },
    rules: {
      "jest/prefer-snapshot-hint": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "jest"
  ],
  "rules": {
    "jest/prefer-snapshot-hint": "error"
  }
}
```

## Related rules

- [vitest/prefer-snapshot-hint](https://lintradar.dev/rules/vitest/prefer-snapshot-hint.md): Enforce including a hint with external snapshots
- [jest/prefer-mock-return-shorthand](https://lintradar.dev/rules/jest/prefer-mock-return-shorthand.md): Prefer mock return shorthands
- [jest/prefer-todo](https://lintradar.dev/rules/jest/prefer-todo.md): Suggest using `test.todo`
- [jest/prefer-mock-promise-shorthand](https://lintradar.dev/rules/jest/prefer-mock-promise-shorthand.md): Prefer mock resolved/rejected shorthands for promises
- [jest/require-hook](https://lintradar.dev/rules/jest/require-hook.md): Require setup and teardown code to be within a hook
- [jest/prefer-jest-mocked](https://lintradar.dev/rules/jest/prefer-jest-mocked.md): Prefer `jest.mocked()` over `fn as jest.Mock`

---

Web page: https://lintradar.dev/rules/jest/prefer-snapshot-hint. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
