File tree 4 files changed +65
-3
lines changed
4 files changed +65
-3
lines changed Original file line number Diff line number Diff line change 28
28
- [ localVue] ( api/options.md#localvue )
29
29
- [ attachToDocument] ( api/options.md#attachtodocument )
30
30
- [ attrs] ( api/options.md#attrs )
31
+ - [ propsData] ( api/options.md#propsdata )
31
32
- [ listeners] ( api/options.md#listeners )
32
- - [ parentComponent] ( api/options.md#parentComponent )
33
+ - [ parentComponent] ( api/options.md#parentcomponent )
33
34
- [ provide] ( api/options.md#provide )
34
35
- [ sync] ( api/options.md#sync )
35
36
- [ その他のオプション] ( api/options.md#その他のオプション )
Original file line number Diff line number Diff line change 10
10
- [ ` localVue ` ] ( #localvue )
11
11
- [ ` attachToDocument ` ] ( #attachtodocument )
12
12
- [ ` attrs ` ] ( #attrs )
13
+ - [ ` propsData ` ] ( #propsdata )
13
14
- [ ` listeners ` ] ( #listeners )
14
- - [ ` parentComponent ` ] ( #parentComponent )
15
+ - [ ` parentComponent ` ] ( #parentcomponent )
15
16
- [ ` provide ` ] ( #provide )
16
17
- [ ` sync ` ] ( #sync )
17
18
@@ -202,6 +203,33 @@ expect(wrapper.vm.$route).toBeInstanceOf(Object)
202
203
203
204
コンポーネントインスタンスの ` $attrs ` オブジェクトを設定します。
204
205
206
+ ## propsData
207
+
208
+ - 型: ` Object `
209
+
210
+ コンポーネントがマウントされる時、コンポーネントインスタンスの props をセットします。
211
+
212
+ 例:
213
+
214
+ ``` js
215
+ const Component = {
216
+ template: ' <div>{{ msg }}</div>' ,
217
+ props: [' msg' ]
218
+ }
219
+ const wrapper = mount (Component, {
220
+ propsData: {
221
+ msg: ' aBC'
222
+ }
223
+ })
224
+ expect (wrapper .text ()).toBe (' aBC' )
225
+ ```
226
+
227
+ ::: 注意
228
+ ` propsData ` は Vue Test Utils のマウンティングオプションではなく [ Vue API] ( https://vuejs.org/v2/api/#propsData ) です。
229
+ この ` propsData ` は [ ` extends ` ] ( https://vuejs.org/v2/api/#extends ) を内部で利用しています。
230
+ 詳しくは[ その他のオプション] ( #その他のオプション ) を参照してください。
231
+ :::
232
+
205
233
## listeners
206
234
207
235
- 型: ` Object `
@@ -231,6 +259,25 @@ expect(wrapper.vm.$parent.$options.name).toBe('foo')
231
259
232
260
コンポーネントに指定したプロパティを注入します。[ provide/inject] ( https://vuejs.org/v2/api/#provide-inject ) を参照してください。
233
261
262
+ 例:
263
+
264
+ ``` js
265
+ const Component = {
266
+ inject: [' foo' ],
267
+ template: ' <div>{{this.foo()}}</div>'
268
+ }
269
+
270
+ const wrapper = shallowMount (Component, {
271
+ provide: {
272
+ foo () {
273
+ return ' fooValue'
274
+ }
275
+ }
276
+ })
277
+
278
+ expect (wrapper .text ()).toBe (' fooValue' )
279
+ ```
280
+
234
281
## sync
235
282
236
283
- 型: ` boolean `
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ describe('Foo', () => {
90
90
foo: ' <div />'
91
91
}
92
92
})
93
- expect (wrapper .find (' div' )).toBe (true )
93
+ expect (wrapper .contains (' div' )).toBe (true )
94
94
})
95
95
})
96
96
```
Original file line number Diff line number Diff line change @@ -131,6 +131,20 @@ mount(Component, {
131
131
})
132
132
```
133
133
134
+ ### スタブコンポーネント
135
+
136
+ ` stubs ` オプションを使用して、グローバルまたはローカルに登録されたコンポーネントを上書きできます:
137
+
138
+ ``` js
139
+ import { mount } from ' @vue/test-utils'
140
+
141
+ mount (Component, {
142
+ // globally-registered-component を空のスタブとして
143
+ // 解決します
144
+ stubs: [' globally-registered-component' ]
145
+ })
146
+ ```
147
+
134
148
### ルーティングの扱い
135
149
136
150
定義によるルーティングは、アプリケーションの全体的な構造と関連し、複数のコンポーネントが関係するため、統合テストまたはエンドツーエンドテストによってよくテストされます。
You can’t perform that action at this time.
0 commit comments