File tree Expand file tree Collapse file tree 12 files changed +204
-2
lines changed Expand file tree Collapse file tree 12 files changed +204
-2
lines changed Original file line number Diff line number Diff line change 3939 * [ isEmpty] ( api/wrapper/isEmpty.md )
4040 * [ isVueInstance] ( api/wrapper/isVueInstance.md )
4141 * [ name] ( api/wrapper/name.md )
42+ * [ setComputed] ( api/wrapper/setComputed.md )
4243 * [ setData] ( api/wrapper/setData.md )
4344 * [ setMethods] ( api/wrapper/setMethods.md )
4445 * [ setProps] ( api/wrapper/setProps.md )
5657 * [ is] ( api/wrapper-array/is.md )
5758 * [ isEmpty] ( api/wrapper-array/isEmpty.md )
5859 * [ isVueInstance] ( api/wrapper-array/isVueInstance.md )
60+ * [ setComputed] ( api/wrapper-array/setComputed.md )
5961 * [ setData] ( api/wrapper-array/setData.md )
6062 * [ setMethods] ( api/wrapper-array/setMethods.md )
6163 * [ setProps] ( api/wrapper-array/setProps.md )
6264 * [ trigger] ( api/wrapper-array/trigger.md )
6365 * [ update] ( api/wrapper-array/update.md )
6466 * [ destroy] ( api/wrapper-array/destroy.md )
67+ * [ 组件] ( api/components/README.md )
68+ * [ TransitionStub] ( api/components/TransitionStub.md )
69+ * [ TransitionGroupStub] ( api/components/TransitionGroupStub.md )
6570 * [ 选择器] ( api/selectors.md )
6671 * [ createLocalVue] ( api/createLocalVue.md )
72+ * [ 配置] ( api/config.md )
Original file line number Diff line number Diff line change 3737 * [ isEmpty] ( api/wrapper/isEmpty.md )
3838 * [ isVueInstance] ( api/wrapper/isVueInstance.md )
3939 * [ name] ( api/wrapper/name.md )
40+ * [ setComputed] ( api/wrapper/setComputed.md )
4041 * [ setData] ( api/wrapper/setData.md )
4142 * [ setMethods] ( api/wrapper/setMethods.md )
4243 * [ setProps] ( api/wrapper/setProps.md )
5455 * [ is] ( api/wrapper-array/is.md )
5556 * [ isEmpty] ( api/wrapper-array/isEmpty.md )
5657 * [ isVueInstance] ( api/wrapper-array/isVueInstance.md )
58+ * [ setComputed] ( api/wrapper-array/setComputed.md )
5759 * [ setData] ( api/wrapper-array/setData.md )
5860 * [ setMethods] ( api/wrapper-array/setMethods.md )
5961 * [ setProps] ( api/wrapper-array/setProps.md )
6062 * [ trigger] ( api/wrapper-array/trigger.md )
6163 * [ update] ( api/wrapper-array/update.md )
6264 * [ destroy] ( api/wrapper-array/destroy.md )
65+ * [ 组件] ( api/components/README.md )
66+ * [ TransitionStub] ( api/components/TransitionStub.md )
67+ * [ TransitionGroupStub] ( api/components/TransitionGroupStub.md )
6368 * [ 选择器] ( api/selectors.md )
6469 * [ createLocalVue] ( api/createLocalVue.md )
70+ * [ 配置] ( api/config.md )
Original file line number Diff line number Diff line change 2727 * [ isEmpty] ( ./wrapper/isEmpty.md )
2828 * [ isVueInstance] ( ./wrapper/isVueInstance.md )
2929 * [ name] ( ./wrapper/name.md )
30+ * [ setComputed] ( ./wrapper/setComputed.md )
3031 * [ setData] ( ./wrapper/setData.md )
3132 * [ setMethods] ( ./wrapper/setMethods.md )
3233 * [ setProps] ( ./wrapper/setProps.md )
4445 * [ is] ( ./wrapper-array/is.md )
4546 * [ isEmpty] ( ./wrapper-array/isEmpty.md )
4647 * [ isVueInstance] ( ./wrapper-array/isVueInstance.md )
48+ * [ setComputed] ( ./wrapper-array/setComputed.md )
4749 * [ setData] ( ./wrapper-array/setData.md )
4850 * [ setMethods] ( ./wrapper-array/setMethods.md )
4951 * [ setProps] ( ./wrapper-array/setProps.md )
5052 * [ trigger] ( ./wrapper-array/trigger.md )
5153 * [ update] ( ./wrapper-array/update.md )
5254 * [ destroy] ( ./wrapper-array/destroy.md )
55+ * [ 组件] ( ./components/README.md )
56+ * [ TransitionStub] ( ./components/TransitionStub.md )
57+ * [ TransitionGroupStub] ( ./components/TransitionGroupStub.md )
5358* [ 选择器] ( ./selectors.md )
5459* [ createLocalVue] ( ./createLocalVue.md )
60+ * [ 配置] ( ./config.md )
Original file line number Diff line number Diff line change 1+ # 组件
2+
3+ ` vue-test-utils ` 包含了用做存根的实用组件。
4+
5+ 默认情况下 [ TransitionStub] ( ./TransitionStub.md ) 和 [ TransitionGroupStub] ( ./TransitionGroupStub.md ) 用来存根 ` transition ` 和 ` transition-group ` 组件。你也可以通过配置信息来编辑存根。
Original file line number Diff line number Diff line change 1+ # ` TransitionGroupStub `
2+
3+ 一个用来存根 ` transition-group ` 包裹器组件的组件。与其异步完成过渡动画不同的是,它会同步返回子组件。
4+
5+ 它在 ` vue-test-utils ` 默认配置中用来存根所有的 ` transition-group ` 组件。将 ` config.stubs['transition-group'] ` 设为 ` false ` 可以使用内建的 ` transition-group ` 包裹器组件:
6+
7+ ``` js
8+ import VueTestUtils from ' vue-test-utils'
9+
10+ VueTestUtils .config .stubs [' transition-group' ] = false
11+ ```
12+
13+ 将其重置可以存根过渡组件:
14+
15+ ``` js
16+ import VueTestUtils , { TransitionGroupStub } from ' vue-test-utils'
17+
18+ VueTestUtils .config .stubs [' transition-group' ] = TransitionGroupStub
19+ ```
20+
21+ 还可以在挂载选项中将其设置为一个存根:
22+
23+ ``` js
24+ import { mount , TransitionGroupStub } from ' vue-test-utils'
25+
26+ mount (Component, {
27+ stubs: {
28+ ' transition-group' : TransitionGroupStub
29+ }
30+ })
31+ ```
Original file line number Diff line number Diff line change 1+ # ` TransitionStub `
2+
3+ 一个用来存根 ` transition ` 包裹器组件的组件。与其异步完成过渡动画不同的是,它会同步返回子组件。
4+
5+ 它在 ` vue-test-utils ` 默认配置中用来存根所有的 ` transition ` 组件。将 ` config.stubs.transition ` 设为 ` false ` 可以使用内建的 ` transition ` 包裹器组件:
6+
7+
8+ ``` js
9+ import VueTestUtils from ' vue-test-utils'
10+
11+ VueTestUtils .config .stubs .transition = false
12+ ```
13+
14+ 将其重置可以存根过渡组件:
15+
16+ ``` js
17+ import VueTestUtils , { TransitionStub } from ' vue-test-utils'
18+
19+ VueTestUtils .config .stubs .transition = TransitionStub
20+ ```
21+
22+ 还可以在挂载选项中将其设置为一个存根:
23+
24+ ``` js
25+ import { mount , TransitionStub } from ' vue-test-utils'
26+
27+ mount (Component, {
28+ stubs: {
29+ transition: TransitionStub
30+ }
31+ })
32+ ```
Original file line number Diff line number Diff line change 1+ # 配置
2+
3+ ` vue-test-utils ` 包含了一个定义其选项的配置对象。
4+
5+ ## ` vue-test-utils ` 配置选项
6+
7+ ### ` stubs `
8+
9+ - 类型:` Object `
10+ - 默认值:`{
11+ transition: TransitionStub,
12+ 'transition-group': TransitionGroupStub
13+ }`
14+
15+ 用到的组件存根。它们会被传入挂载选项的 ` stubs ` 复写。
16+
17+ 当把 ` stubs ` 作为一个数组传入挂载选项时,` config.stubs ` 会被转换为一个数组,然后用只返回一个 div 的基础组件进行存根。
18+
19+ 示例:
20+
21+ ``` js
22+ import VueTestUtils from ' vue-test-utils'
23+
24+ VueTestUtils .config .stubs [' my-compomnent' ] = ' <div />'
25+ ```
Original file line number Diff line number Diff line change 11# 选择器
22
3- 很多方法的参数中都包含选择器。一个选择器可以是一个 CSS 选择器或是一个 Vue 组件 。
3+ 很多方法的参数中都包含选择器。一个选择器可以是一个 CSS 选择器、一个 Vue 组件或是一个查找选项对象 。
44
55## CSS 选择器
66
@@ -41,3 +41,14 @@ import Foo from './Foo.vue'
4141const wrapper = shallow (Foo)
4242expect (wrapper .is (Foo)).toBe (true )
4343```
44+
45+ ## 查找选项对象
46+
47+ ### Ref
48+
49+ ` vue-test-utils ` 允许通过一个查找选项对象在组件包裹器上根据 ` $ref ` 选择元素。
50+
51+ ``` js
52+ const buttonWrapper = wrapper .find ({ ref: ' myButton' });
53+ buttonWrapper .trigger (' click' );
54+ ```
Original file line number Diff line number Diff line change 1+ # ` setComputed(computedObjects) `
2+
3+ 为 ` WrapperArray ` 的每个 ` Wrapper ` ` vm ` 都设置计算属性并强行更新。
4+
5+ ** 注意:该包裹器必须包含一个 Vue 示例。**
6+ ** 注意:每个 Vue 示例必须已经有被传入 ` setComputed ` 的计算属性。**
7+
8+ - ** 参数:**
9+ - ` {Object} computed properties `
10+
11+ - ** 示例:**
12+
13+ ``` js
14+ import { mount } from ' vue-test-utils'
15+ import Foo from ' ./Foo.vue'
16+ import Bar from ' ./Bar.vue'
17+
18+ const wrapper = mount (Foo)
19+ const barArray = wrapper .findAll (Bar)
20+
21+ barArray .setComputed ({
22+ computed1: ' new-computed1' ,
23+ computed2: ' new-computed2'
24+ })
25+ ```
Original file line number Diff line number Diff line change @@ -31,3 +31,16 @@ expect(wrapper.emitted().foo.length).toBe(2)
3131// 断言事件的有效数据
3232expect (wrapper .emitted ().foo [1 ]).toEqual ([123 ])
3333```
34+
35+ 你也可以把上面的代码写成这样:
36+
37+ ``` js
38+ // 断言事件已经被触发
39+ expect (wrapper .emitted (' foo' )).toBeTruthy ()
40+
41+ // 断言事件的数量
42+ expect (wrapper .emitted (' foo' ).length ).toBe (2 )
43+
44+ // 断言事件的有效数据
45+ expect (wrapper .emitted (' foo' )[1 ]).toEqual ([123 ])
46+ ```
You can’t perform that action at this time.
0 commit comments