Test a mod changedplugins/mods/test
Nearest release: v2.1.336, published an hour after upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 3 Dec 2026 17:07 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 3 Dec 2026 17:37 UTC.
Upstream edited
Recorded here
Lines+20added
Lines−1removed
From line
176
where the diff opens
First seen
1 Oct 2026
this site's first read of the page
Recorded edits17to this page, all time
### Pass options to a test
The whole hunk
from line 176, old and new numbered
/
from line 176
176176| `session.start` | `() => ({ cwd: '/work' })` |
177177| `turn.start` | `($, e) => ({ turnId: e.turnId })` |
178178| `tool.call` | `() => ({ result: '...' })` |
179| `turn.complete` | `() => ({ text: '' })`. Fire it with `$.turn.complete({ turnId, answer, durationMs, isAborted: false, usage: null })`. |
179| `turn.complete` | `() => ({ text: '' })`. Fire it with `$.turn.complete({ turnId: '...', reason: 'answer', answer: '...', durationMs: 0, isAborted: false })`. |
180180| `prompt.submit` | `($, e) => ({ text: e.text })` |
181181| `prompt.fill` | `() => ({ isFilled: true })` |
182182| `$.prompt.read` | `() => ({ value: { text: '...', cursor: 0 } })` |
from line 193
193193`expect` has its own set of assertions, such as `toEqual` and `toHaveLength`, which go after the value you're checking, as in `expect(answer.text).toBe('ok')`. For the full list, search `claude-code/index.d.ts` in [the types for your build](https://code.claude.com/docs/en/plugins/mods/create.md#get-the-types-for-your-build) for `type Matchers`. Put `.not` before the assertion to check the opposite. To check what a promise settles with, put `.resolves` or `.rejects` right after `expect(...)` and `await` the line, as in `await expect(promise).rejects.toThrow()`.
194194
195195When an `expect` fails inside a stub or hook that you passed to `on` as a plain function rather than an async generator, the test fails. The engine skips that hook, and the failure output names it, such as `in the test's store.set hook`.
196
197### Pass options to a test
198
199To give a test more time or set your mod's configuration, pass an object between the name and the body, as in `test(name, { timeoutMs, options }, body)`. The object takes these fields, plus the `plugins` array shown in [Test a policy mod](#test-a-mod-that-judges-other-mods):
200
201* **`timeoutMs`**: the test's timeout in milliseconds, 5000 by default. A test that runs longer fails with an error such as `timed out after 5000 ms`.
202* **`options`**: the [`userConfig`](https://code.claude.com/docs/en/plugins/components#user-configuration) values for the mod under test. Your mod's `register(on, options)` function receives them, with the manifest's defaults filled in for values you omit.
203
204This test is for a mod whose manifest declares a `greeting` value in `userConfig` and whose `/hello` command replies with it. The test sets `greeting` to `yo`, sets a 10-second timeout, and checks the reply:
205
206```typescript theme={null}
207import { expect, test } from 'claude-code/testing'
208
209test('greets with the configured word', { options: { greeting: 'yo' }, timeoutMs: 10000 }, async ($, on) => {
210 // The first call on $ loads your mod, so its register receives { greeting: 'yo' } plus the manifest's other defaults
211 const answer = await $.command.run({ command: 'hello', args: '' })
212 expect(answer.text).toBe('yo')
213})
214```
196215
197216## Test a timer
198217
No line in this hunk matches that.