aboutsummaryrefslogtreecommitdiff
path: root/docs/guides/test/update-snapshots.md
blob: 412b78a85a0112ebbb88a524477a0aa189403781 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
name: Update snapshots in `bun test`
---

Bun's test runner supports Jest-style snapshot testing via `.toMatchSnapshot()`.

{% callout %}
The `.toMatchInlineSnapshot()` method is not yet supported.
{% /callout %}

```ts#snap.test.ts
import { test, expect } from "bun:test";

test("snapshot", () => {
  expect({ foo: "bar" }).toMatchSnapshot();
});
```

---

The first time this test is executed, Bun will write a snapshot file to disk in a directory called `__snapshots__` that lives alongside the test file.

```txt
test
├── __snapshots__
│   └── snap.test.ts.snap
└── snap.test.ts
```

---

To regenerate snapshots, use the `--update-snapshots` flag.

```sh
$ bun test --update-snapshots
bun test v1.x (9c68abdb)

test/snap.test.ts:
✓ snapshot [0.86ms]

 1 pass
 0 fail
 snapshots: +1 added # the snapshot was regenerated
 1 expect() calls
Ran 1 tests across 1 files. [102.00ms]
```

---

See [Docs > Test Runner > Snapshots](/docs/test/mocks) for complete documentation on mocking with the Bun test runner.
er 1-9/+10 2022-02-04Update test_command.zigGravatar Jarred Sumner 1-2/+0 2022-02-04`path.normalize()` tests passGravatar Jarred Sumner 2-146/+213 2022-02-03Fix test failures in path.joinGravatar Jarred Sumner 1-8/+115 2022-02-03Update mimalloc_arena.zigGravatar Jarred Sumner 1-0/+9 2022-02-03[bun test] Support multiple filesGravatar Jarred Sumner 1-2/+12 2022-02-03Update js_ast.zigGravatar Jarred Sumner 1-0/+1 2022-02-03Support loading multiple entry points by changing what `bun:main` points toGravatar Jarred Sumner 6-4/+36 2022-02-03[bun install] Configurable max http retry countGravatar Jarred Sumner 1-0/+7 2022-02-03Missing newline in errors in bun installGravatar Jarred Sumner 1-4/+8 2022-02-03Fix bug with http clientGravatar Jarred Sumner 6-107/+101 2022-02-03Move detectFastRefresh to later so HTTP request handler starts fasterGravatar Jarred Sumner 1-2/+1 2022-02-03Fix bug with macro remaps in Bun.Transpiler apiGravatar Jarred Sumner 2-5/+8 2022-02-03Slight improvement to non-ascii file path handlingGravatar Jarred Sumner 4-18/+79 2022-02-02`path.relative` passes Node's tests (which also fixed bugs)Gravatar Jarred Sumner 8-283/+571