From 109ebc14fda92bc2c84459b9911bef03b08f1b0a Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Thu, 6 Jul 2023 13:02:29 -0700 Subject: 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 --- docs/cli/test.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'docs/cli/test.md') 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. -- cgit v1.2.3