.toMatchSnapshot()
.
The first time this test is executed, Bun will evaluate the value passed into
expect()
and write it to disk in a directory called __snapshots__
that lives alongside the test file. (Note the snapshots: +1 added
line in the output.)
terminal
The
__snapshots__
directory contains a .snap
file for each test file in the directory.
File Tree
The
snap.test.ts.snap
file is a JavaScript file that exports a serialized version of the value passed into expect()
. The {foo: "bar"}
object has been serialized to JSON.
snap.test.ts.snap
Later, when this test file is executed again, Bun will read the snapshot file and compare it to the value passed into
expect()
. If the values are different, the test will fail.
terminal
To update snapshots, use the
--update-snapshots
flag.
terminal
See Docs > Test Runner > Snapshots for complete documentation on snapshots with the Bun test runner.