File tree Expand file tree Collapse file tree 16 files changed +188
-34
lines changed Expand file tree Collapse file tree 16 files changed +188
-34
lines changed Original file line number Diff line number Diff line change @@ -65,9 +65,11 @@ Vue Test Utils 是 Vue.js 官方的单元测试实用工具库。
6565 * [ is] ( api/wrapper-array/is.md )
6666 * [ isEmpty] ( api/wrapper-array/isEmpty.md )
6767 * [ isVueInstance] ( api/wrapper-array/isVueInstance.md )
68+ * [ setChecked] ( api/wrapper-array/setChecked.md )
6869 * [ setData] ( api/wrapper-array/setData.md )
6970 * [ setMethods] ( api/wrapper-array/setMethods.md )
7071 * [ setProps] ( api/wrapper-array/setProps.md )
72+ * [ setValue] ( api/wrapper-array/setValue.md )
7173 * [ trigger] ( api/wrapper-array/trigger.md )
7274 * [ isVisible] ( api/wrapper-array/isVisible.md )
7375 * [ 组件] ( api/components/ )
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ Vue Test Utils 包含了一个定义其选项的配置对象。
66
77### ` stubs `
88
9- - 类型:` Object `
9+ - 类型:` { [name: string]: Component | boolean | string } `
1010- 默认值:`{
1111 transition: TransitionStub,
1212 'transition-group': TransitionGroupStub
@@ -46,7 +46,7 @@ VueTestUtils.config.mocks['$store'] = {
4646
4747### ` methods `
4848
49- - 类型:` Object `
49+ - 类型:` { [name: string]: Function } `
5050- 默认值:` {} `
5151
5252你可以使用 ` config ` 对象配置默认的方法。它可以用于为组件注入方法的插件,例如 [ VeeValidate] ( https://vee-validate.logaretm.com/ ) 。你可以通过在挂载选项中传入 ` methods ` 来覆写 ` config ` 中的方法集合。
@@ -94,3 +94,18 @@ import VueTestUtils from '@vue/test-utils'
9494
9595VueTestUtils .config .logModifiedComponents = false
9696```
97+
98+ ### ` silent `
99+
100+ - 类型:` Boolean `
101+ - 默认值:` true `
102+
103+ 在组件的可观察内容 (如 props) 发生突变时,警告会被 Vue 阻止。当设置为 ` false ` 时,所有的警告都会出现在控制台中。这是一个 ` Vue.config.silent ` 的配置方式。
104+
105+ 示例;
106+
107+ ``` js
108+ import VueTestUtils from ' @vue/test-utils'
109+
110+ VueTestUtils .config .silent = false
111+ ```
Original file line number Diff line number Diff line change 1111- [ ` attachToDocument ` ] ( #attachtodocument )
1212- [ ` attrs ` ] ( #attrs )
1313- [ ` listeners ` ] ( #listeners )
14+ - [ ` parentComponent ` ] ( #parentComponent )
1415- [ ` provide ` ] ( #provide )
1516- [ ` sync ` ] ( #sync )
1617
@@ -106,7 +107,9 @@ shallowMount(Component, {
106107 stubs: {
107108 // 使用一个特定的实现作为存根
108109 ' registered-component' : Foo,
109- // 使用创建默认的实现作为存根
110+ // 使用创建默认的实现作为存根。
111+ // 这里默认存根的组件名是 `another-component`。
112+ // 默认存根是 `<${the component name of default stub}-stub>`。
110113 ' another-component' : true
111114 }
112115})
@@ -180,6 +183,23 @@ expect(wrapper.vm.$route).toBeInstanceOf(Object)
180183
181184设置组件实例的 ` $listeners ` 对象。
182185
186+ ## parentComponent
187+
188+ - 类型:` Object `
189+
190+ 用来作为被挂载组件的父级组件。
191+
192+ 示例:
193+
194+ ``` js
195+ import Foo from ' ./Foo.vue'
196+
197+ const wrapper = shallowMount (Component, {
198+ parentComponent: Foo
199+ })
200+ expect (wrapper .vm .$parent .name ).toBe (' foo' )
201+ ```
202+
183203## provide
184204
185205- 类型:` Object `
Original file line number Diff line number Diff line change 77 - ` {Object} context `
88 - ` {Array<Component|Object>|Component} children `
99 - ` {Object} slots `
10- - ` {Array<Componet |Object>|Component|String} default `
11- - ` {Array<Componet |Object>|Component|String} named `
10+ - ` {Array<Component |Object>|Component|String} default `
11+ - ` {Array<Component |Object>|Component|String} named `
1212 - ` {Object} mocks `
1313 - ` {Object|Array<string>} stubs `
1414 - ` {Vue} localVue `
Original file line number Diff line number Diff line change 77 - ` {Object} context `
88 - ` {Array<Component|Object>|Component} children `
99 - ` {Object} slots `
10- - ` {Array<Componet |Object>|Component|String} default `
11- - ` {Array<Componet |Object>|Component|String} named `
10+ - ` {Array<Component |Object>|Component|String} default `
11+ - ` {Array<Component |Object>|Component|String} named `
1212 - ` {Object} mocks `
1313 - ` {Object|Array<string>} stubs `
1414 - ` {Vue} localVue `
Original file line number Diff line number Diff line change 1010
1111### ` length `
1212
13- ` number ` :该 ` WrapperArray ` 中包含的 ` Wrapper ` 的数量。
13+ ` number ` (只读) :该 ` WrapperArray ` 中包含的 ` Wrapper ` 的数量。
1414
1515## 方法
1616
2121!!!include(docs/zh/api/wrapper-array/is.md)!!!
2222!!!include(docs/zh/api/wrapper-array/isEmpty.md)!!!
2323!!!include(docs/zh/api/wrapper-array/isVueInstance.md)!!!
24+ !!!include(docs/zh/api/wrapper-array/setChecked.md)!!!
2425!!!include(docs/zh/api/wrapper-array/setData.md)!!!
2526!!!include(docs/zh/api/wrapper-array/setMethods.md)!!!
2627!!!include(docs/zh/api/wrapper-array/setProps.md)!!!
28+ !!!include(docs/zh/api/wrapper-array/setValue.md)!!!
2729!!!include(docs/zh/api/wrapper-array/trigger.md)!!!
Original file line number Diff line number Diff line change 1+ ## setChecked(checked)
2+
3+ 该方法是接下来这段代码的别名:
4+
5+ ``` js
6+ wrapperArray .wrappers .forEach (wrapper => wrapper .setChecked (checked))
7+ ```
8+
9+ - ** 参数:**
10+ - ` {Boolean} checked (default: true) `
11+
12+ - ** 示例:**
13+
14+ ``` js
15+ import { mount } from ' @vue/test-utils'
16+
17+ const wrapper = mount ({
18+ data () {
19+ return {
20+ t1: false ,
21+ t2: ' '
22+ }
23+ },
24+ template: `
25+ <div>
26+ <input type="checkbox" name="t1" class="foo" v-model="t1" />
27+ <input type="radio" name="t2" class="foo" value="foo" v-model="t2"/>
28+ <input type="radio" name="t2" class="bar" value="bar" v-model="t2"/>
29+ </div>`
30+ })
31+
32+ const wrapperArray = wrapper .findAll (' .foo' )
33+ expect (wrapper .vm .t1 ).to .equal (false )
34+ expect (wrapper .vm .t2 ).to .equal (' ' )
35+ wrapperArray .setChecked ()
36+ expect (wrapper .vm .t1 ).to .equal (true )
37+ expect (wrapper .vm .t2 ).to .equal (' foo' )
38+ ```
Original file line number Diff line number Diff line change 11## setData(data)
22
3- 为 ` WrapperArray ` 的每个 ` Wrapper ` ` vm ` 都设置数据并强行更新 。
3+ 为 ` WrapperArray ` 的每个 ` Wrapper ` ` vm ` 都设置数据 。
44
55** 注意:该包裹器必须包含一个 Vue 示例。**
66
Original file line number Diff line number Diff line change 1+ ## setValue(value)
2+
3+ 该方法是接下来这段代码的别名:
4+
5+ ``` js
6+ wrapperArray .wrappers .forEach (wrapper => wrapper .setValue (value))
7+ ```
8+
9+ - ** 参数:**
10+ - ` {any} value `
11+
12+ - ** 示例:**
13+
14+ ``` js
15+ import { mount } from ' @vue/test-utils'
16+
17+ const wrapper = mount ({
18+ data () {
19+ return {
20+ t1: ' ' ,
21+ t2: ' '
22+ }
23+ },
24+ template: `
25+ <div>
26+ <input type="text" name="t1" class="foo" v-model="t1" />
27+ <input type="text" name="t2" class="foo" v-model="t2"/>
28+ </div>`
29+ })
30+
31+ const wrapperArray = wrapper .findAll (' .foo' )
32+ expect (wrapper .vm .t1 ).to .equal (' ' )
33+ expect (wrapper .vm .t2 ).to .equal (' ' )
34+ wrapperArray .setValue (' foo' )
35+ expect (wrapper .vm .t1 ).to .equal (' foo' )
36+ expect (wrapper .vm .t2 ).to .equal (' foo' )
37+ ```
Original file line number Diff line number Diff line change @@ -6,23 +6,23 @@ Vue Test Utils 是一个基于包裹器的 API。
66
77## 属性
88
9- ### ` vm `
9+ ### ` vm `
1010
11- ` Component ` :这是该 Vue 实例。你可以通过 ` wrapper.vm ` 访问一个实例所有的[ 方法和属性] ( https://vuejs.org/v2/api/#Instance-Properties ) 。这只存在于 Vue 组件包裹器中 。
11+ ` Component ` (只读) :这是该 Vue 实例。你可以通过 ` wrapper.vm ` 访问一个实例所有的[ 方法和属性] ( https://vuejs.org/v2/api/#Instance-Properties ) 。这只存在于 Vue 组件包裹器或绑定了 Vue 组件包裹器的 HTMLElement 中 。
1212
13- ### ` element `
13+ ### ` element `
1414
15- ` HTMLElement ` :包裹器的根 DOM 节点
15+ ` HTMLElement ` (只读) :包裹器的根 DOM 节点
1616
17- ### ` options `
17+ ### ` options `
1818
19- #### ` options.attachedToDom `
19+ #### ` options.attachedToDom `
2020
21- ` Boolean ` :如果 ` attachToDom ` 传递给了 ` mount ` 或 ` shallowMount ` 则为真
21+ ` Boolean ` (只读) :如果 ` attachToDom ` 传递给了 ` mount ` 或 ` shallowMount ` 则为真
2222
23- #### ` options.sync `
23+ #### ` options.sync `
2424
25- ` Boolean ` :如果挂载选项里的 ` sync ` 不是 ` false ` 则为真
25+ ` Boolean ` (只读) :如果挂载选项里的 ` sync ` 不是 ` false ` 则为真
2626
2727## 方法
2828
You can’t perform that action at this time.
0 commit comments