From e8403cef180498e222134a3f3e30efbb2c7d5d60 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 24 Sep 2018 01:39:03 +0900 Subject: [PATCH 1/4] docs(ja): pick up diff from original docs --- docs/ja/README.md | 3 ++- docs/ja/api/options.md | 49 ++++++++++++++++++++++++++++++++++- docs/ja/api/shallowMount.md | 2 +- docs/ja/guides/common-tips.md | 13 ++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/docs/ja/README.md b/docs/ja/README.md index 48e242311..3d2617e7b 100644 --- a/docs/ja/README.md +++ b/docs/ja/README.md @@ -28,8 +28,9 @@ - [localVue](api/options.md#localvue) - [attachToDocument](api/options.md#attachtodocument) - [attrs](api/options.md#attrs) + - [propsData](api/options.md#propsdata) - [listeners](api/options.md#listeners) - - [parentComponent](api/options.md#parentComponent) + - [parentComponent](api/options.md#parentcomponent) - [provide](api/options.md#provide) - [sync](api/options.md#sync) - [その他のオプション](api/options.md#その他のオプション) diff --git a/docs/ja/api/options.md b/docs/ja/api/options.md index 932aee94c..b007299b6 100644 --- a/docs/ja/api/options.md +++ b/docs/ja/api/options.md @@ -10,8 +10,9 @@ - [`localVue`](#localvue) - [`attachToDocument`](#attachtodocument) - [`attrs`](#attrs) +- [`propsData`](#propsdata) - [`listeners`](#listeners) -- [`parentComponent`](#parentComponent) +- [`parentComponent`](#parentcomponent) - [`provide`](#provide) - [`sync`](#sync) @@ -202,6 +203,33 @@ expect(wrapper.vm.$route).toBeInstanceOf(Object) コンポーネントインスタンスの `$attrs` オブジェクトを設定します。 +## propsData + +- type: `Object` + +Set the component instance's props when the component is mounted. + +Example: + +```js +const Component = { + template: '
{{ msg }}
', + props: ['msg'] +} +const wrapper = mount(Component, { + propsData: { + msg: 'aBC' + } +}) +expect(wrapper.text()).toBe('aBC') +``` + +::: tip +It's worth noting that `propsData` is actually a [Vue API](https://vuejs.org/v2/api/#propsData), not a +Vue Test Utils mounting option. It is processed through [`extends`](https://vuejs.org/v2/api/#extends). +Please see [Other options](#other-options). +::: + ## listeners - 型: `Object` @@ -231,6 +259,25 @@ expect(wrapper.vm.$parent.$options.name).toBe('foo') コンポーネントに指定したプロパティを注入します。[provide/inject](https://vuejs.org/v2/api/#provide-inject) を参照してください。 +Example: + +```js +const Component = { + inject: ['foo'], + template: '
{{this.foo()}}
' +} + +const wrapper = shallowMount(Component, { + provide: { + foo () { + return 'fooValue' + } + } +}) + +expect(wrapper.text()).toBe('fooValue') +``` + ## sync - 型: `boolean` diff --git a/docs/ja/api/shallowMount.md b/docs/ja/api/shallowMount.md index 6a3c24710..00a4f6ea3 100644 --- a/docs/ja/api/shallowMount.md +++ b/docs/ja/api/shallowMount.md @@ -90,7 +90,7 @@ describe('Foo', () => { foo: '
' } }) - expect(wrapper.find('div')).toBe(true) + expect(wrapper.contains('div')).toBe(true) }) }) ``` diff --git a/docs/ja/guides/common-tips.md b/docs/ja/guides/common-tips.md index f139cccc8..bf586f33e 100644 --- a/docs/ja/guides/common-tips.md +++ b/docs/ja/guides/common-tips.md @@ -131,6 +131,19 @@ mount(Component, { }) ``` +### Stubbing components + +You can override components that are registered globally or locally by using the `stubs` option: + + ```js +import { mount } from '@vue/test-utils' + mount(Component, { + // Will resolve globally-registered-component with + // empty stub + stubs: ['globally-registered-component'] +}) +``` + ### ルーティングの扱い 定義によるルーティングは、アプリケーションの全体的な構造と関連し、複数のコンポーネントが関係するため、統合テストまたはエンドツーエンドテストによってよくテストされます。 From b570a1a76e9ea9edb9683ca482f433e8c68987a6 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 24 Sep 2018 02:01:26 +0900 Subject: [PATCH 2/4] docs(ja): translate previous commits --- docs/ja/api/options.md | 16 ++++++++-------- docs/ja/guides/common-tips.md | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/ja/api/options.md b/docs/ja/api/options.md index b007299b6..6b60bed60 100644 --- a/docs/ja/api/options.md +++ b/docs/ja/api/options.md @@ -205,11 +205,11 @@ expect(wrapper.vm.$route).toBeInstanceOf(Object) ## propsData -- type: `Object` +- 型: `Object` -Set the component instance's props when the component is mounted. +コンポーネントがマウントされる時、コンポーネントインスタンスの props をセットします。 -Example: +例: ```js const Component = { @@ -224,10 +224,10 @@ const wrapper = mount(Component, { expect(wrapper.text()).toBe('aBC') ``` -::: tip -It's worth noting that `propsData` is actually a [Vue API](https://vuejs.org/v2/api/#propsData), not a -Vue Test Utils mounting option. It is processed through [`extends`](https://vuejs.org/v2/api/#extends). -Please see [Other options](#other-options). +::: 注意 +`propsData` は Vue Test Utils のマウティングオプションではなく [Vue API](https://vuejs.org/v2/api/#propsData) です。 +この `propsData` は [`extends`](https://vuejs.org/v2/api/#extends) を内部で利用しています。 +詳しくは[その他のオプション](#その他のオプション)を参照してください。 ::: ## listeners @@ -259,7 +259,7 @@ expect(wrapper.vm.$parent.$options.name).toBe('foo') コンポーネントに指定したプロパティを注入します。[provide/inject](https://vuejs.org/v2/api/#provide-inject) を参照してください。 -Example: +例: ```js const Component = { diff --git a/docs/ja/guides/common-tips.md b/docs/ja/guides/common-tips.md index bf586f33e..80ca8d77b 100644 --- a/docs/ja/guides/common-tips.md +++ b/docs/ja/guides/common-tips.md @@ -131,15 +131,15 @@ mount(Component, { }) ``` -### Stubbing components +### スタブコンポーネント -You can override components that are registered globally or locally by using the `stubs` option: +グローバルまたは `stubs` オプションを使用してローカルに登録されたコンポーネントを上書きできます: ```js import { mount } from '@vue/test-utils' mount(Component, { - // Will resolve globally-registered-component with - // empty stub + // 空スタブによってグローバルに登録されたコンポーネントを + // 解決します stubs: ['globally-registered-component'] }) ``` From fe699655947e9176af4748cf127d95de34d135b9 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Wed, 26 Sep 2018 00:08:02 +0900 Subject: [PATCH 3/4] docs(ja): fix lint errors --- docs/ja/guides/common-tips.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/ja/guides/common-tips.md b/docs/ja/guides/common-tips.md index 80ca8d77b..8c5e82a6c 100644 --- a/docs/ja/guides/common-tips.md +++ b/docs/ja/guides/common-tips.md @@ -135,9 +135,10 @@ mount(Component, { グローバルまたは `stubs` オプションを使用してローカルに登録されたコンポーネントを上書きできます: - ```js +```js import { mount } from '@vue/test-utils' - mount(Component, { + +mount(Component, { // 空スタブによってグローバルに登録されたコンポーネントを // 解決します stubs: ['globally-registered-component'] From 68123e0e609b8e51b2b3df90478baa08ed668387 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Wed, 26 Sep 2018 13:13:16 +0900 Subject: [PATCH 4/4] docs(ja): fix docs --- docs/ja/api/options.md | 2 +- docs/ja/guides/common-tips.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/ja/api/options.md b/docs/ja/api/options.md index 6b60bed60..685deeeba 100644 --- a/docs/ja/api/options.md +++ b/docs/ja/api/options.md @@ -225,7 +225,7 @@ expect(wrapper.text()).toBe('aBC') ``` ::: 注意 -`propsData` は Vue Test Utils のマウティングオプションではなく [Vue API](https://vuejs.org/v2/api/#propsData) です。 +`propsData` は Vue Test Utils のマウンティングオプションではなく [Vue API](https://vuejs.org/v2/api/#propsData) です。 この `propsData` は [`extends`](https://vuejs.org/v2/api/#extends) を内部で利用しています。 詳しくは[その他のオプション](#その他のオプション)を参照してください。 ::: diff --git a/docs/ja/guides/common-tips.md b/docs/ja/guides/common-tips.md index 8c5e82a6c..02b622e9f 100644 --- a/docs/ja/guides/common-tips.md +++ b/docs/ja/guides/common-tips.md @@ -133,13 +133,13 @@ mount(Component, { ### スタブコンポーネント -グローバルまたは `stubs` オプションを使用してローカルに登録されたコンポーネントを上書きできます: +`stubs` オプションを使用して、グローバルまたはローカルに登録されたコンポーネントを上書きできます: ```js import { mount } from '@vue/test-utils' mount(Component, { - // 空スタブによってグローバルに登録されたコンポーネントを + // globally-registered-component を空のスタブとして // 解決します stubs: ['globally-registered-component'] })