Skip to content

update docs/ja #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/ja/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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#その他のオプション)
Expand Down
49 changes: 48 additions & 1 deletion docs/ja/api/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
- [`localVue`](#localvue)
- [`attachToDocument`](#attachtodocument)
- [`attrs`](#attrs)
- [`propsData`](#propsdata)
- [`listeners`](#listeners)
- [`parentComponent`](#parentComponent)
- [`parentComponent`](#parentcomponent)
- [`provide`](#provide)
- [`sync`](#sync)

Expand Down Expand Up @@ -202,6 +203,33 @@ expect(wrapper.vm.$route).toBeInstanceOf(Object)

コンポーネントインスタンスの `$attrs` オブジェクトを設定します。

## propsData

- 型: `Object`

コンポーネントがマウントされる時、コンポーネントインスタンスの props をセットします。

例:

```js
const Component = {
template: '<div>{{ msg }}</div>',
props: ['msg']
}
const wrapper = mount(Component, {
propsData: {
msg: 'aBC'
}
})
expect(wrapper.text()).toBe('aBC')
```

::: 注意
`propsData` は Vue Test Utils のマウンティングオプションではなく [Vue API](https://vuejs.org/v2/api/#propsData) です。
この `propsData` は [`extends`](https://vuejs.org/v2/api/#extends) を内部で利用しています。
詳しくは[その他のオプション](#その他のオプション)を参照してください。
:::

## listeners

- 型: `Object`
Expand Down Expand Up @@ -231,6 +259,25 @@ expect(wrapper.vm.$parent.$options.name).toBe('foo')

コンポーネントに指定したプロパティを注入します。[provide/inject](https://vuejs.org/v2/api/#provide-inject) を参照してください。

例:

```js
const Component = {
inject: ['foo'],
template: '<div>{{this.foo()}}</div>'
}

const wrapper = shallowMount(Component, {
provide: {
foo () {
return 'fooValue'
}
}
})

expect(wrapper.text()).toBe('fooValue')
```

## sync

- 型: `boolean`
Expand Down
2 changes: 1 addition & 1 deletion docs/ja/api/shallowMount.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('Foo', () => {
foo: '<div />'
}
})
expect(wrapper.find('div')).toBe(true)
expect(wrapper.contains('div')).toBe(true)
})
})
```
Expand Down
14 changes: 14 additions & 0 deletions docs/ja/guides/common-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ mount(Component, {
})
```

### スタブコンポーネント

`stubs` オプションを使用して、グローバルまたはローカルに登録されたコンポーネントを上書きできます:

```js
import { mount } from '@vue/test-utils'

mount(Component, {
// globally-registered-component を空のスタブとして
// 解決します
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • globally-registered-component は スタブの名前なので、そのまま利用した方が良さそうに思いました。
修正案: globally-registered-component を空のスタブとして解決します。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かにそうですね。そのように修正します!

stubs: ['globally-registered-component']
})
```

### ルーティングの扱い

定義によるルーティングは、アプリケーションの全体的な構造と関連し、複数のコンポーネントが関係するため、統合テストまたはエンドツーエンドテストによってよくテストされます。
Expand Down