# bun:test/no-large-snapshots

> Disallow snapshots that are longer than a set number of lines

Nobody reads a several-hundred-line snapshot in a review. When it changes, people update it without looking, and then the test passes no matter what the code does. A short snapshot, or an assertion on the few values that matter, still tells you something when it fails.

The rule counts the lines of the snapshot in `toMatchInlineSnapshot` and `toThrowErrorMatchingInlineSnapshot`. The limit is 50 lines. Snapshots in `.snap` files aren't checked.

{/* 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]
"bun:test/no-large-snapshots" = "error" # or "warn"
```

Every option, set to its default. The ones that are commented out are unset by default.

```toml bunfig.toml
[lint.rules]
"bun:test/no-large-snapshots" = ["error", {
  # inlineMaxSize = <number>,
  maxSize = 50,
}]
```

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

## Examples

These examples set `inlineMaxSize` to `3` to stay short.

Reported:

{/* bad {"options": [{"inlineMaxSize": 3}]} */}
```ts
import { expect, test } from "bun:test";

test("loads the user", () => {
  expect(loadUser(1)).toMatchInlineSnapshot(`
    {
      "email": "ada@example.com",
      "id": 1,
      "name": "Ada",
    }
  `);
});
```

{/* bad {"options": [{"inlineMaxSize": 3}]} */}
```ts
import { expect, test } from "bun:test";

test("creates a user", () => {
  expect(createUser("Ada")).toMatchInlineSnapshot({ id: expect.any(Number) }, `
    {
      "email": null,
      "id": Any<Number>,
      "name": "Ada",
    }
  `);
});
```

Not reported:

{/* good {"options": [{"inlineMaxSize": 3}]} */}
```ts
import { expect, test } from "bun:test";

test("loads the user", () => {
  const user = loadUser(1);
  expect(user.name).toBe("Ada");
  expect(user.email).toMatchInlineSnapshot(`"ada@example.com"`);
});
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `inlineMaxSize` | the value of `maxSize` | The most lines an inline snapshot can have. |
| `maxSize` | `50` | The limit to use when `inlineMaxSize` isn't set. |

```toml bunfig.toml
[lint.rules]
"bun:test/no-large-snapshots" = ["error", { inlineMaxSize = 20 }]
```

Without `inlineMaxSize`, `maxSize` applies:

{/* bad {"options": [{"maxSize": 3}]} */}
```ts
import { expect, test } from "bun:test";

test("lists the roles", () => {
  expect(roles()).toMatchInlineSnapshot(`
    [
      "admin",
      "editor",
      "viewer",
    ]
  `);
});
```
