Skip to content

Commit 11655d2

Browse files
mikakanekazupon
authored andcommitted
"Unit Testing" の翻訳 vuejs#147 (vuejs#166)
* Unit Testの章の翻訳完了 * Unit Testの章の翻訳修正 * Unit Testの章の翻訳修正 * 全角スペースの除去 * 修正漏れの対応
1 parent df481d0 commit 11655d2

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/guide/unit-testing.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
2-
title: Unit Testing
2+
title: ユニットテスト
33
type: guide
44
order: 22
55
---
66

7-
## Setup and Tooling
7+
## テストツールとセットアップ
88

9-
Anything compatible with a module-based build system will work, but if you're looking for a specific recommendation, try the [Karma](http://karma-runner.github.io/0.12/index.html) test runner. It has a lot of community plugins, including support for [Webpack](https://github.com/webpack/karma-webpack) and [Browserify](https://github.com/Nikku/karma-browserify). For detailed setup, please refer to each project's respective documentation, though these example Karma configurations for [Webpack](https://github.com/vuejs/vue-loader-example/blob/master/build/karma.conf.js) and [Browserify](https://github.com/vuejs/vueify-example/blob/master/karma.conf.js) may help you get started.
9+
テストツールは、モジュールベースのビルドシステムで動作するものならどのようなものでも問題ありませんが、テストツールを探している場合、[Karma](http://karma-runner.github.io/0.12/index.html)を試してみましょう。 Karma には多くのコミュニティ製プラグインが存在し、[Webpack](https://github.com/webpack/karma-webpack)[Browserify](https://github.com/Nikku/karma-browserify)へのサポートも充実しています。 Karma の設定例として、[Webpack](https://github.com/vuejs/vue-loader-example/blob/master/build/karma.conf.js) [Browserify](https://github.com/vuejs/vueify-example/blob/master/karma.conf.js)のサンプル設定が最初のスタートに役立ちますが、詳しいセットアップについては、各テストツールのドキュメントを確認して下さい。
1010

11-
## Simple Assertions
11+
## 単純なテスト
1212

13-
In terms of code structure for testing, you don't have to do anything special in your components to make them testable. Just export the raw options:
13+
テスト設計の観点から、コンポーネントのテスタビリティを向上させるためにコンポーネント内で特別な何かを行う必要はありません。単純に options をエクスポートするだけです。
1414

1515
``` html
1616
<template>
@@ -31,36 +31,36 @@ In terms of code structure for testing, you don't have to do anything special in
3131
</script>
3232
```
3333

34-
When you test that component, all you have to do is import the object along with Vue to make many common assertions:
34+
コンポーネントをテストする際には、 Vue と合わせて options のオブジェクトをインポートし、検証を実施します。
3535

3636
``` js
37-
// Import Vue and the component being tested
37+
// Vue と テスト対象のコンポーネントをインポートする
3838
import Vue from 'vue'
3939
import MyComponent from 'path/to/MyComponent.vue'
4040

41-
// Here are some Jasmine 2.0 tests, though you can
42-
// use any test runner / assertion library combo you prefer
41+
// テストランナーや検証には、どのようなライブラリを用いても構いませんが
42+
// ここでは Jasmine 2.0 を用いたテスト記述を行っています。
4343
describe('MyComponent', () => {
44-
// Inspect the raw component options
44+
// コンポーネントの options を直接検証します。
4545
it('has a created hook', () => {
4646
expect(typeof MyComponent.created).toBe('function')
4747
})
4848

49-
// Evaluate the results of functions in
50-
// the raw component options
49+
// コンポーネントの options 内にある関数を実行し、
50+
// 結果を検証します。
5151
it('sets the correct default data', () => {
5252
expect(typeof MyComponent.data).toBe('function')
5353
const defaultData = MyComponent.data()
5454
expect(defaultData.message).toBe('hello!')
5555
})
5656

57-
// Inspect the component instance on mount
57+
// コンポーネントインスタンスをマウントして検証します。
5858
it('correctly sets the message when created', () => {
5959
const vm = new Vue(MyComponent).$mount()
6060
expect(vm.message).toBe('bye!')
6161
})
6262

63-
// Mount an instance and inspect the render output
63+
// マウントされたコンポーネントインスタンスを描画して検証します。
6464
it('renders the correct message', () => {
6565
const Ctor = Vue.extend(MyComponent)
6666
const vm = new Ctor().$mount()
@@ -69,9 +69,9 @@ describe('MyComponent', () => {
6969
})
7070
```
7171

72-
## Writing Testable Components
72+
## テストしやすいコンポーネントの記述
7373

74-
A lot of components' render output are primarily determined by the props they receive. In fact, if a component's render output solely depends on its props, it becomes quite straightforward to test, similar to asserting the return value of a pure function with different arguments. Take an contrived example:
74+
コンポーネントの描画結果は、コンポーネントの受け取る props によってその大半が決定されます。実際、コンポーネントの描画結果が、単に props の値によってのみ決まる場合、異なる引数を用いた関数の戻り値の検証と同じ様に、シンプルに考えることができます。例を見てみましょう。
7575

7676
``` html
7777
<template>
@@ -85,13 +85,13 @@ A lot of components' render output are primarily determined by the props they re
8585
</script>
8686
```
8787

88-
You can assert its render output with different props using the `propsData` option:
88+
`propsData`オプションを利用して、異なる props を用いた描画結果の検証が可能です。
8989

9090
``` js
9191
import Vue from 'vue'
9292
import MyComponent from './MyComponent.vue'
9393

94-
// helper function that mounts and returns the rendered text
94+
// コンポーネントをマウントし描画結果を返すヘルパー関数
9595
function getRenderedText (Component, propsData) {
9696
const Ctor = Vue.extend(MyComponent)
9797
const vm = new Ctor({ propsData }).$mount()
@@ -111,22 +111,22 @@ describe('MyComponent', () => {
111111
})
112112
```
113113

114-
## Asserting Asynchronous Updates
114+
## 非同期な更新の検証
115115

116-
Since Vue [performs DOM updates asynchronously](/guide/reactivity.html#Async-Update-Queue), assertions on DOM updates resulting from state change will have to be made in a `Vue.nextTick` callback:
116+
Vue [非同期に DOM の更新を行う](/guide/reactivity.html#Async-Update-Queue) ため、 state の変更に対する DOM の更新に関する検証は、 `Vue.nextTick` コールバックを用いて行う必要があります。
117117

118118
``` js
119-
// Inspect the generated HTML after a state update
119+
// state の更新後、生成された HTML の検証を行う
120120
it('updates the rendered message when vm.message updates', done => {
121121
const vm = new Vue(MyComponent).$mount()
122122
vm.message = 'foo'
123123

124-
// wait a "tick" after state change before asserting DOM updates
124+
// state 変更後、 DOM が更新されるまでの "tick" で待機する
125125
Vue.nextTick(() => {
126126
expect(vm.$el.textContent).toBe('foo')
127127
done()
128128
})
129129
})
130130
```
131131

132-
We are planning to work on a collection of common test helpers that makes it even simpler to render components with different constraints (e.g. shallow rendering that ignores child components) and assert their output.
132+
私たちは、コンポーネントを特別な状態で描画し検証する(例えば、子コンポーネントを無視した浅い描画など)ような、テストをより簡単にするためのヘルパーセットの開発も検討しています。

0 commit comments

Comments
 (0)