Agent Wranglers

Test quality Recommended

Keep snapshot tests small and reviewed

Use snapshots only for small, stable output. Review every snapshot change like code, and never accept new snapshots without reading them.

How to do it

Prefer plain assertions on the fields that matter. When a snapshot helps, keep it under 50 lines and inline, such as toMatchInlineSnapshot() in Vitest or Jest, or inline-snapshot in Python. Never run the update flag just to make a red build green. Screenshot comparisons, such as Playwright's toHaveScreenshot(), need fixed fonts, data and browser versions.

Example

test('formats the order summary', () => {
  expect(formatSummary(makeOrder({ total: 1999 }))).toMatchInlineSnapshot(`"1 item, 19.99 EUR"`);
});
# Python with inline-snapshot
from inline_snapshot import snapshot

def test_formats_the_order_summary():
    assert format_summary(make_order(total=1999)) == snapshot("1 item, 19.99 EUR")

How to check

In continuous integration, a missing or changed snapshot fails the run instead of being written, as with Jest's --ci flag. No stored text snapshot is longer than 50 lines.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers testing playbook: https://agentwranglers.se/playbook/testing/test-quality/small-snapshots.