Skip to content

Commit ebda934

Browse files
committed
chore: merge
2 parents d2c4ab5 + 22b909e commit ebda934

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2314
-203
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ npm install --save-dev @vue/server-test-utils
1616
```
1717

1818
## Peer Dependencies
19-
You need to install `vue-template-compiler` which is used to compiled components. It should be the same version as the version of Vue you are using.
19+
You need to install `vue-template-compiler` which is used to compile components. It should be the same version as the version of Vue you are using.
2020

2121
```
2222
npm install --save-dev vue-template-compiler
@@ -35,7 +35,7 @@ Refer to the [documentation](https://vue-test-utils.vuejs.org/)
3535

3636
## Questions
3737

38-
For questions and support please use the [Discord chat room](https://vue-land.js.org/), [Gitter chat room](https://gitter.im/vuejs/vue), or [the official forum](http://forum.vuejs.org). The issue list of this repo is **exclusively** for bug reports and feature requests.
38+
For questions and support please use the [Discord chat room](https://vue-land.js.org/) or [the official forum](http://forum.vuejs.org). The issue list of this repo is **exclusively** for bug reports and feature requests.
3939

4040
## Issues
4141

docs/.vuepress/config.js

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ module.exports = {
2424
serviceWorker: true,
2525
theme: 'vue',
2626
themeConfig: {
27+
algolia: {
28+
apiKey: 'ee1b8516c9e5a5be9b6c25684eafc42f',
29+
indexName: 'vue_test_utils'
30+
},
2731
repo: 'vuejs/vue-test-utils',
2832
docsDir: 'docs',
2933
editLinks: true,

docs/api/options.md

+48-2
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ Options for `mount` and `shallowMount`. The options object can contain both Vue
99
- [`mocks`](#mocks)
1010
- [`localVue`](#localvue)
1111
- [`attachToDocument`](#attachtodocument)
12+
- [`propsData`](#propsdata)
1213
- [`attrs`](#attrs)
1314
- [`listeners`](#listeners)
14-
- [`parentComponent`](#parentComponent)
15+
- [`parentComponent`](#parentcomponent)
1516
- [`provide`](#provide)
1617
- [`sync`](#sync)
1718

1819
## context
1920

2021
- type: `Object`
2122

22-
Passes context to functional component. Can only be used with functional components.
23+
Passes context to functional component. Can only be used with [functional components](https://vuejs.org/v2/guide/render-function.html#Functional-Components).
2324

2425
Example:
2526

@@ -206,6 +207,32 @@ Component will be attached to DOM when rendered if set to `true`.
206207

207208
Set the component instance's `$attrs` object.
208209

210+
## propsData
211+
212+
- type: `Object`
213+
214+
Set the component instance's props.
215+
216+
Example:
217+
218+
```js
219+
const Component = {
220+
template: '<div>{{ msg }}</div>',
221+
props: ['msg']
222+
}
223+
const wrapper = mount(Component, {
224+
propsData: {
225+
msg: 'aBC'
226+
}
227+
})
228+
expect(wrapper.text()).toBe('aBC')
229+
```
230+
231+
::: tip
232+
It's worth noting that `propsData` is actually a [Vue API](https://vuejs.org/v2/api/#propsData), not a
233+
`vue-test-utils` option. It is processed through [`extends`](#other-options).
234+
:::
235+
209236
## listeners
210237

211238
- type: `Object`
@@ -235,6 +262,25 @@ expect(wrapper.vm.$parent.name).toBe('foo')
235262

236263
Pass properties for components to use in injection. See [provide/inject](https://vuejs.org/v2/api/#provide-inject).
237264

265+
Example:
266+
267+
```js
268+
const Component = {
269+
inject: ['foo'],
270+
template: '<div>{{this.foo()}}</div>'
271+
}
272+
273+
const wrapper = shallowMount(Component, {
274+
provide: {
275+
foo () {
276+
return 'fooValue'
277+
}
278+
}
279+
})
280+
281+
expect(wrapper.text()).toBe('fooValue')
282+
```
283+
238284
## sync
239285

240286
- type: `boolean`

docs/api/shallowMount.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('Foo', () => {
8989
foo: '<div />'
9090
}
9191
})
92-
expect(wrapper.find('div')).toBe(true)
92+
expect(wrapper.contains('div')).toBe(true)
9393
})
9494
})
9595
```

docs/guides/testing-async-components.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ The implementation of the `axios` mock looks like this:
88

99
``` js
1010
export default {
11-
get: () => new Promise(resolve => {
12-
resolve({ data: 'value' })
13-
})
11+
get: () => Promise.resolve({ data: 'value' })
1412
}
1513
```
1614

docs/guides/using-with-typescript.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this guide, we'll walk through how to setup a testing setup for a TypeScript
1111
First you need to create a project. If you don't have Vue CLI installed, install it globally:
1212

1313
```shell
14-
$ npm install -g @vue/cli-service-global
14+
$ npm install -g @vue/cli
1515
```
1616

1717
And create a project by running:

docs/ja/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [Mocha + webpack による単一ファイルコンポーネントのテスト](guides/testing-single-file-components-with-mocha-webpack.md)
1212
* [Karma による単一ファイルコンポーネントのテスト](guides/testing-single-file-components-with-karma.md)
1313
* [非同期動作のテスト](guides/testing-async-components.md)
14+
* [TypeScript と一緒に使う](guides/using-with-typescript.md)
1415
* [Vue Router と一緒に使う](guides/using-with-vue-router.md)
1516
* [Vuex と一緒に使う](guides/using-with-vuex.md)
1617
* [API](api/)

docs/ja/api/options.md

+35-13
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,52 @@ expect(wrapper.find('div')).toBe(true)
6565

6666
## scopedSlots
6767

68-
- 型: `{ [name: string]: string }`
68+
- 型: `{ [name: string]: string|Function }`
6969

70-
コンポーネントにスコープ付きスロットのコンテンツのオブジェクトを渡します。key はスロット名に対応します。値はテンプレート文字列を指定します
70+
コンポーネントにスコープ付きスロットのオブジェクトを提供します。そのオブジェクトのキーはスロット名になります
7171

72-
3つ制限事項があります
72+
slot-scope 属性を使って props を指定することができます
7373

74-
* [email protected]+ のみをサポートします。
74+
```js
75+
shallowMount(Component, {
76+
scopedSlots: {
77+
foo: '<p slot-scope="foo">{{foo.index}},{{foo.text}}</p>'
78+
}
79+
})
80+
```
7581

76-
* `<template>` タグを `scopedSlots` オプションのルート要素として使用することはできません
82+
slot-scope 属性を使って props を指定しない場合、スロットが展開されると `props` という変数名で props を使用することができます
7783

78-
* PhantomJS をサポートしません。
79-
代わりに [Puppeteer](https://github.com/karma-runner/karma-chrome-launcher#headless-chromium-with-puppeteer) を使用してください。
84+
```js
85+
shallowMount(Component, {
86+
scopedSlots: {
87+
default: '<p>{{props.index}},{{props.text}}</p>'
88+
}
89+
})
90+
```
8091

81-
例:
92+
props を引数に取る関数を渡すことができます。
8293

8394
```js
84-
const wrapper = shallowMount(Component, {
95+
shallowMount(Component, {
96+
scopedSlots: {
97+
foo: function (props) {
98+
return this.$createElement('div', props.index)
99+
}
100+
}
101+
})
102+
```
103+
104+
または、 JSX を使用することができます。メソッド内に JSX を書いた場合、`this.$createElement` は babel-plugin-transform-vue-jsx によって自動的に注入されます。
105+
106+
```js
107+
shallowMount(Component, {
85108
scopedSlots: {
86-
foo: '<p slot-scope="props">{{props.index}},{{props.text}}</p>'
109+
foo (props) {
110+
return <div>{ props.text }</div>
111+
}
87112
}
88113
})
89-
expect(wrapper.find('#fooWrapper').html()).toBe(
90-
`<div id="fooWrapper"><p>0,text1</p><p>1,text2</p><p>2,text3</p></div>`
91-
)
92114
```
93115

94116
## stubs

docs/ja/guides/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
!!!include(docs/ja/guides/testing-single-file-components-with-mocha-webpack.md)!!!
99
!!!include(docs/ja/guides/testing-single-file-components-with-karma.md)!!!
1010
!!!include(docs/ja/guides/testing-async-components.md)!!!
11+
!!!include(docs/ja/guides/using-with-typescript.md)!!!
1112
!!!include(docs/ja/guides/using-with-vue-router.md)!!!
12-
!!!include(docs/ja/guides/using-with-vuex.md)!!!
13+
!!!include(docs/ja/guides/using-with-vuex.md)!!!

docs/ja/guides/testing-async-components.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
``` js
1010
export default {
11-
get: () => new Promise(resolve => {
12-
resolve({ data: 'value' })
13-
})
11+
get: () => Promise.resolve({ data: 'value' })
1412
}
1513
```
1614

docs/ja/guides/testing-single-file-components-with-jest.md

+33-26
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ npm install --save-dev vue-jest
4747
],
4848
"transform": {
4949
// vue-jest で *.vue ファイルを処理する
50-
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
50+
".*\\.(vue)$": "vue-jest"
5151
}
5252
}
5353
}
@@ -122,31 +122,6 @@ webpack で `babel-preset-env` を使用するとした場合、webpack は ES M
122122
}
123123
```
124124

125-
### スナップショットテスト
126-
127-
[`vue-server-renderer`](https://github.com/vuejs/vue/tree/dev/packages/vue-server-renderer) を使ってコンポーネントを文字列に描画して保存することができます。[Jest のスナップショットテスト](https://facebook.github.io/jest/docs/en/snapshot-testing.html) のスナップショットとして表示されます。
128-
129-
`vue-server-renderer` の描画結果には、いくつかの SSR (Server-Side Rendering: サーバサイドレンダリング) 固有の属性が含まれており、空白を無視するため、diff をスキャンするのが難しくなります。カスタムシリアライザを使用して、保存されたスナップショットを改善することができます。
130-
131-
``` bash
132-
npm install --save-dev jest-serializer-vue
133-
```
134-
135-
次に `package.json` で設定します:
136-
137-
``` json
138-
{
139-
// ...
140-
"jest": {
141-
// ...
142-
// スナップショットのシリアライザ
143-
"snapshotSerializers": [
144-
"<rootDir>/node_modules/jest-serializer-vue"
145-
]
146-
}
147-
}
148-
```
149-
150125
### テストファイルの配置
151126

152127
デフォルトでは、Jest はプロジェクト全体で `.spec.js` または `.test.js` 拡張子を持つすべてのファイルを再帰的に取得します。これがあなたのニーズに合わない場合は、`package.json` ファイルの config セクションで[testRegex を変更する](https://facebook.github.io/jest/docs/en/configuration.html#testregex-string)ことが可能です。
@@ -202,6 +177,38 @@ describe('Component', () => {
202177
})
203178
```
204179

180+
### スナップショットテスト
181+
182+
Vue Test Utils でコンポーネントをマウントすると、コンポーネントのルート HTML 要素にアクセスすることができます。 [Jest のスナップショットテスト](https://facebook.github.io/jest/docs/en/snapshot-testing.html)で使用するためにこれを保存することができます。
183+
184+
```js
185+
test('renders correctly', () => {
186+
const wrapper = mount(Component)
187+
expect(wrapper.element).toMatchSnapshot()
188+
})
189+
```
190+
191+
カスタムシリアライザを使用することによって保存されたスナップショットを改善することができます。
192+
193+
``` bash
194+
npm install --save-dev jest-serializer-vue
195+
```
196+
197+
`package.json` でその設定をします。
198+
199+
``` json
200+
{
201+
// ...
202+
"jest": {
203+
// ...
204+
// スナップショットに対するシリアライズ
205+
"snapshotSerializers": [
206+
"jest-serializer-vue"
207+
]
208+
}
209+
}
210+
```
211+
205212
### リソース
206213

207214
- [このセットアップのプロジェクト例](https://github.com/vuejs/vue-test-utils-jest-example)

0 commit comments

Comments
 (0)