File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ Vue 选项会在一个新的实例被创建的时候传递给组件。比如 `st
13
13
- [ ` localVue ` ] ( #localvue )
14
14
- [ ` attachToDocument ` ] ( #attachtodocument )
15
15
- [ ` attrs ` ] ( #attrs )
16
+ - [ ` provide ` ] ( #provide )
16
17
- [ ` listeners ` ] ( #listeners )
17
18
- [ ` clone ` ] ( #clone )
18
19
@@ -160,6 +161,8 @@ expect(wrapper.vm.$route).toBeInstanceOf(Object)
160
161
161
162
如果为 ` true ` 则会在挂载之前克隆组件。这样做会回避原始组件定义的突变。
162
163
163
- ` options.mocks ` ( ` Object ` ):向 Vue 实例添加全局属性。
164
+ ### ` provide `
164
165
165
- ` options.localVue ` (` Object ` ):在 ` mount ` 中使用的 ` Vue ` 类。请移步 [ ` createLocalVue ` ] ( createLocalVue.md ) 。
166
+ - 类型:` Object `
167
+
168
+ 为组件传递用于注入的属性。可查阅 [ provie/inject] ( https://cn.vuejs.org/v2/api/#provide-inject ) 了解更多。
Original file line number Diff line number Diff line change @@ -110,6 +110,34 @@ Vue 会异步的将未生效的 DOM 更新批量应用,以避免因数据反
110
110
111
111
* 注意:当你需要为诸如异步回调或 Promise 解析等操作显性改进为事件循环的时候,` nextTick ` 仍然是必要的。*
112
112
113
+ 如果你仍然需要在自己的测试文件中使用 ` nextTick ` ,注意任何在其内部被抛出的错误可能都不会被测试运行器捕获,因为其内部使用了 Promise。关于这个问题有两个建议:要么你可以在测试的一开始将 Vue 的全局错误处理器设置为 ` done ` 回调,要么你可以在调用 ` nextTick ` 时不带参数让其作为一个 Promise 返回:
114
+
115
+ ``` js
116
+ // 这不会被捕获
117
+ it (' will time out' , (done ) => {
118
+ Vue .nextTick (() => {
119
+ expect (true ).toBe (false )
120
+ done ()
121
+ })
122
+ })
123
+
124
+ // 接下来的两项测试都会如预期工作
125
+ it (' will catch the error using done' , (done ) => {
126
+ Vue .config .errorHandler = done
127
+ Vue .nextTick (() => {
128
+ expect (true ).toBe (false )
129
+ done ()
130
+ })
131
+ })
132
+
133
+ it (' will catch the error using a promise' , () => {
134
+ return Vue .nextTick ()
135
+ .then (function () {
136
+ expect (true ).toBe (false )
137
+ })
138
+ })
139
+ ```
140
+
113
141
## 下一步是什么
114
142
115
143
- [ 选择一个测试运行器] ( ./choosing-a-test-runner.md ) 以把 ` vue-test-utils ` 集成到你的工程里。
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ describe('Actions.vue', () => {
91
91
})
92
92
```
93
93
94
- 这里发生了什么?首先我们用 ` Vue .use` 方法告诉 Vue 使用 Vuex。这只是 ` Vue.use ` 的一个包裹器。
94
+ 这里发生了什么?首先我们用 ` localVue .use` 方法告诉 Vue 使用 Vuex。这只是 ` Vue.use ` 的一个包裹器。
95
95
96
96
然后我们用 ` new Vuex.store ` 伪造了一个 store 并填入假数据。我们只把它传递给 action,因为我们只关心这个。
97
97
You can’t perform that action at this time.
0 commit comments