Skip to content

Commit

Permalink
fixup: docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous committed Nov 2, 2024
1 parent 0fbfb18 commit efe2f8c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,21 @@ when(overloaded).calledWith().thenReturn(null)
when<() => null>(overloaded).calledWith().thenReturn(null)
```

#### Fallback

By default, if arguments do not match, a vitest-when stub will no-op and return `undefined`. You can customize this fallback by configuring your own unconditional behavior on the mock using Vitest's built-in [mock API][].

```ts
const spy = vi.fn().mockReturnValue('you messed up!')

subject.when(spy).calledWith('hello').thenReturn('world')

spy('hello') // "world"
spy('jello') // "you messed up!"
```

[mock API]: https://vitest.dev/api/mock.html

### `.thenReturn(value: TReturn)`

When the stubbing is satisfied, return `value`
Expand Down

0 comments on commit efe2f8c

Please sign in to comment.