diff --git a/docs/zh-cn/api/config.md b/docs/zh-cn/api/config.md index 1e629d254..b27ce54e3 100644 --- a/docs/zh-cn/api/config.md +++ b/docs/zh-cn/api/config.md @@ -24,3 +24,58 @@ import VueTestUtils from '@vue/test-utils' VueTestUtils.config.stubs['my-component'] = '
' ``` + +### `mocks` + +- 类型:`Object` +- 默认值:`{}` + +默认使用传递给 `config.mocks` 的值,类似 `stubs`。传递给挂载选项中 `mocks` 对象的任何值都会优先于 `config.mocks` 中的同名声明。 + +示例: + +```js +import VueTestUtils from '@vue/test-utils' + +VueTestUtils.config.mocks['$store'] = { + state: { + id: 1 + } +} +``` + +### `methods` + +- 类型:`Object` +- 默认值:`{}` + +你可以使用 `config` 对象配置默认的方法。它可以用于为组件注入方法的插件,例如 [VeeValidate](https://vee-validate.logaretm.com/)。你可以通过在挂载选项中传入 `methods` 来覆写 `config` 中的方法集合。 + +示例: + +```js +import VueTestUtils from '@vue/test-utils' + +VueTestUtils.config.methods['errors'] = () => { + any: () => false +} +``` + +### `provide` + +- 类型:`Object` +- 默认值:`{}` + +默认使用传递给 `config.provide` 的值,类似 `stubs` 或 `mocks`。传递给挂载选项中 `provide` 对象的任何值都会优先于 `config.provide` 中的同名声明。**请注意这里不支持将函数传递给 `config.provide`。** + +示例: + +```js +import VueTestUtils from '@vue/test-utils' + +VueTestUtils.config.provide['$logger'] = { + log: (...args) => { + console.log(...args) + } +} +``` diff --git a/docs/zh-cn/api/mount.md b/docs/zh-cn/api/mount.md index ff3296dc3..99d7b2eb4 100644 --- a/docs/zh-cn/api/mount.md +++ b/docs/zh-cn/api/mount.md @@ -1,4 +1,4 @@ -# `mount(component {, options}])` +# `mount(component [, options])` - **参数:** diff --git a/docs/zh-cn/api/options.md b/docs/zh-cn/api/options.md index 2ca472cf6..0f597f949 100644 --- a/docs/zh-cn/api/options.md +++ b/docs/zh-cn/api/options.md @@ -6,7 +6,7 @@ - [`context`](#context) - [`slots`](#slots) -- [scopedSlots](#scopedslots) +- [`scopedSlots`](#scopedslots) - [`stubs`](#stubs) - [`mocks`](#mocks) - [`localVue`](#localvue)