# vitest/require-local-test-context-for-concurrent-snapshots

> Require the `expect` of the test context for snapshots in concurrent tests

Concurrent tests run at the same time, so the `expect` you import from `"vitest"` can't tell which test a snapshot belongs to. The snapshot can be saved under another test's name, or compared with another test's snapshot. Use the `expect` that Vitest passes to the test function, which is tied to that test.

The rule checks `toMatchSnapshot`, `toMatchInlineSnapshot`, `toMatchFileSnapshot`, `toThrowErrorMatchingSnapshot` and `toThrowErrorMatchingInlineSnapshot`, in `test.concurrent`, `it.concurrent` and `describe.concurrent`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"vitest/require-local-test-context-for-concurrent-snapshots" = "error"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```js
import { describe, expect, test } from "vitest";

test.concurrent("renders the header", () => {
  expect(render("header")).toMatchSnapshot();
});

describe.concurrent("footer", () => {
  test("renders the links", () => {
    expect(render("links")).toMatchSnapshot();
  });
});
```

Not reported:

{/* good */}
```js
import { expect, test } from "vitest";

test.concurrent("renders the header", ({ expect }) => {
  expect(render("header")).toMatchSnapshot();
});

test.concurrent("renders the footer", (context) => {
  context.expect(render("footer")).toMatchSnapshot();
});

test("renders the sidebar", () => {
  expect(render("sidebar")).toMatchSnapshot();
});
```
