You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/unit-testing.md
+23-23
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
1
---
2
-
title: Unit Testing
2
+
title: ユニットテスト
3
3
type: guide
4
4
order: 22
5
5
---
6
6
7
-
## Setup and Tooling
7
+
## テストツールとセットアップ
8
8
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.
it('correctly sets the message when created', () => {
59
59
constvm=newVue(MyComponent).$mount()
60
60
expect(vm.message).toBe('bye!')
61
61
})
62
62
63
-
//Mount an instance and inspect the render output
63
+
//マウントされたコンポーネントインスタンスを描画して検証します。
64
64
it('renders the correct message', () => {
65
65
constCtor=Vue.extend(MyComponent)
66
66
constvm=newCtor().$mount()
@@ -69,9 +69,9 @@ describe('MyComponent', () => {
69
69
})
70
70
```
71
71
72
-
## Writing Testable Components
72
+
## テストしやすいコンポーネントの記述
73
73
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:
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`コールバックを用いて行う必要があります。
117
117
118
118
```js
119
-
//Inspect the generated HTML after a state update
119
+
//state の更新後、生成された HTML の検証を行う
120
120
it('updates the rendered message when vm.message updates', done=> {
121
121
constvm=newVue(MyComponent).$mount()
122
122
vm.message='foo'
123
123
124
-
//wait a "tick" after state change before asserting DOM updates
124
+
//state 変更後、 DOM が更新されるまでの "tick" で待機する
125
125
Vue.nextTick(() => {
126
126
expect(vm.$el.textContent).toBe('foo')
127
127
done()
128
128
})
129
129
})
130
130
```
131
131
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.
0 commit comments