close

require-local-test-context-for-concurrent-snapshots

Added in v0.8.2

Configuration

PresetConfigured Value
✅ rstestPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, rstestPlugin } from '@rslint/core';

export default defineConfig([
  rstestPlugin.configs.recommended,
  {
    rules: {
      'rstest/require-local-test-context-for-concurrent-snapshots': 'error',
    },
  },
]);

Rule Details

Requires concurrent tests to use the expect from their local Test Context for snapshot assertions. A shared global or imported expect can mix snapshot state between tests that run at the same time.

The rule checks snapshot matchers in concurrent tests, including concurrent suites and parameterized tests. It requires type information to identify the local Test Context.

Incorrect

test.concurrent('renders a user', () => {
  expect(renderUser()).toMatchSnapshot();
});

Correct

test.concurrent('renders a user', ({ expect }) => {
  expect(renderUser()).toMatchSnapshot();
});