See what changed
git diff snapshots/
Update if changes are intentional
bun test --update-snapshots
Commit the updated snapshots
git add snapshots/ git commit -m "Update snapshots after UI changes"
### Cleaning Up Unused Snapshots
Bun will warn about unused snapshots:
warning
Warning: 1 unused snapshot found: my-test.test.ts.snap: "old test that no longer exists 1"
Remove unused snapshots by deleting them from the snapshot files or by running tests with cleanup flags if available.
### Organizing Large Snapshot Files
For large projects, consider organizing tests to keep snapshot files manageable:
directory structure
tests/ ├── components/ │ ├── Button.test.tsx │ └── snapshots/ │ └── Button.test.tsx.snap ├── utils/ │ ├── formatters.test.ts │ └── snapshots/ │ └── formatters.test.ts.snap
## Troubleshooting
### Snapshot Failures
When snapshots fail, you’ll see a diff:
diff
- Expected
-
Received
Object {
- "name": "John",
- "name": "Jane", }
Common causes:
* Intentional changes (update with `--update-snapshots`)
* Unintentional changes (fix the code)
* Dynamic data (use property matchers)
* Environment differences (normalize the data)
### Platform Differences
Be aware of platform-specific differences:
test.ts
// Paths might differ between Windows/Unix test("file operations", () => { const result = processFile("./test.txt");
expect({ ...result, path: result.path.replace(/\/g, "/"), // Normalize paths }).toMatchSnapshot(); });