diff options
| author | 2023-07-06 13:02:29 -0700 | |
|---|---|---|
| committer | 2023-07-06 13:02:29 -0700 | |
| commit | 109ebc14fda92bc2c84459b9911bef03b08f1b0a (patch) | |
| tree | af707758802715fcb567ac88225e0c23e2974dbd /docs/cli/test.md | |
| parent | 95ddfcc4377350b1d604c39c36562bde45fad2a9 (diff) | |
| download | bun-109ebc14fda92bc2c84459b9911bef03b08f1b0a.tar.gz bun-109ebc14fda92bc2c84459b9911bef03b08f1b0a.tar.zst bun-109ebc14fda92bc2c84459b9911bef03b08f1b0a.zip | |
Various docs updates (#3437)
* Various docs updates
* Add mocks page
* Fix make
* WebKit instructions
* Update instructions
* Updates
* Update nodejs compat table
* Document trusted deps
* Tweak trustedDependencies docs
* Document --exact
* Update test docs
* Tweaks
* Boring
* Remove redundant j
* Undo makefile changes
* Undo makefile changes
* Update page title
* Regen
* Undo changes
Diffstat (limited to '')
| -rw-r--r-- | docs/cli/test.md | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/cli/test.md b/docs/cli/test.md index d19a45a12..7af8dcc20 100644 --- a/docs/cli/test.md +++ b/docs/cli/test.md @@ -65,6 +65,24 @@ $ bun test --preload ./setup.ts See [Test > Lifecycle](/docs/test/lifecycle) for complete documentation. +## Mocks + +Create mocks with the `mock` function. Mocks are automatically reset between tests. + +``` +import { test, expect, mock } from "bun:test"; +const random = mock(() => Math.random()); + +test("random", async () => { + const val = random(); + expect(val).toBeGreaterThan(0); + expect(random).toHaveBeenCalled(); + expect(random).toHaveBeenCalledTimes(1); +}); +``` + +See [Test > Mocks](/docs/test/mocks) for complete documentation. + ## Snapshot testing Snapshots are supported by `bun test`. See [Test > Snapshots](/docs/test/snapshots) for complete documentation. |
