Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions runtime/fundamentals/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ Deno.test("database operations", async (t) => {
});
```

## Timeouts

You can set a maximum duration for individual tests using the `timeout` option.
If a test exceeds its deadline it is marked as failed. Both asynchronous hangs
(a promise that never resolves) and synchronous hot loops (`while (true) {}`)
are caught.

```ts
Deno.test({
name: "completes within deadline",
timeout: 5000, // 5 seconds
async fn() {
const response = await fetch("https://example.com");
await response.body?.cancel();
},
});
```

If a test times out the next test in the same file still runs normally.

Setting `timeout` to `0` or omitting it means the test runs without a deadline.

## Test Hooks

Deno provides test hooks that allow you to run setup and teardown code before
Expand Down