Skip to content

docs(en): merge docs-cn/sync-docs into docs-cn/dev @ 7eae51cc #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6f3d705
fix(deps): update all non-major dependencies (#7867)
renovate[bot] Apr 24, 2025
2905288
docs: fix typo (#7886)
Elijer Apr 24, 2025
43966ff
docs: deprecate old context augmentation and recommend test.extend (#…
sheremet-va May 2, 2025
aecfe2c
fix(browser): resolve FS commands relative to the project root (#7896)
sheremet-va May 5, 2025
4f3f3a1
feat: provide `ctx.signal` (#7878)
sheremet-va May 5, 2025
2fd4f42
feat(coverage): v8 experimental AST-aware remapping (#7736)
AriPerkkio May 5, 2025
9a5874b
feat: support custom colors for `test.name` (#7809)
AriPerkkio May 5, 2025
8706c77
feat: add `vi.mockObject` to automock any object (#7761)
hi-ogawa May 5, 2025
0b7a91c
feat(browser): implement `connect` option for `playwright` browser pr…
egfx-notifications May 5, 2025
5c80186
feat: introduce `watchTriggerPatterns` option (#7778)
sheremet-va May 5, 2025
dd5596a
docs: fix example
sheremet-va May 5, 2025
a40aa27
docs: use `extends` instead of `configFile` in `injectTestProjects` (…
romhml May 5, 2025
e906203
feat: deprecate `workspace` in favor of `projects` (#7923)
sheremet-va May 5, 2025
69ccc6e
chore(snapshots): rename `message` to `hint` in method signatures (#7…
k-yle May 6, 2025
8f0fb8c
docs: fix toEqualTypeOf in testing-types.md (#7938)
tkrotoff May 6, 2025
823cf17
docs: minor prose improvements to it.for documentation (#7956)
berzi May 11, 2025
7eae51c
fix: try to catch unhandled error outside of a test (#7968)
sheremet-va May 13, 2025
30e8a93
docs(en): merging all conflicts
docschina-bot May 13, 2025
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
Prev Previous commit
Next Next commit
feat: add vi.mockObject to automock any object (#7761)
Co-authored-by: Vladimir <[email protected]>
  • Loading branch information
hi-ogawa and sheremet-va authored May 5, 2025
commit 8706c77553e1b8b147d509250a01a40381198524
27 changes: 27 additions & 0 deletions api/vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,33 @@ expect(res).toBe(5)
expect(getApples).toHaveNthReturnedWith(2, 5)
```

### vi.mockObject <Version>3.2.0</Version>

- **Type:** `<T>(value: T) => MaybeMockedDeep<T>`

Deeply mocks properties and methods of a given object in the same way as `vi.mock()` mocks module exports. See [automocking](/guide/mocking.html#automocking-algorithm) for the detail.

```ts
const original = {
simple: () => 'value',
nested: {
method: () => 'real'
},
prop: 'foo',
}

const mocked = vi.mockObject(original)
expect(mocked.simple()).toBe(undefined)
expect(mocked.nested.method()).toBe(undefined)
expect(mocked.prop).toBe('foo')

mocked.simple.mockReturnValue('mocked')
mocked.nested.method.mockReturnValue('mocked nested')

expect(mocked.simple()).toBe('mocked')
expect(mocked.nested.method()).toBe('mocked nested')
```

### vi.isMockFunction

- **Type:** `(fn: Function) => boolean`
Expand Down