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
This is the component we want to test. It calls Vuex actions.
9
+
これはテストしたいコンポーネントです。これは Vuex のアクションを呼び出します。
10
10
11
11
```html
12
12
<template>
@@ -35,13 +35,13 @@ export default{
35
35
</script>
36
36
```
37
37
38
-
For the purposes of this test, we don’t care what the actions do, or what the store looks like. We just need to know that these actions are being fired when they should, and that they are fired with the expected value.
Instead of passing the store to the base Vue constructor, we can pass it to a - [localVue](../api/options.md#localvue). A localVue is a scoped Vue constructor that we can make changes to without affecting the global Vue constructor.
The actions are [jest mock functions](https://facebook.github.io/jest/docs/en/mock-functions.html). These mock functions give us methods to assert whether the actions were called or not.
We can then assert in our tests that the action stub was called when expected.
100
+
アクションのスタブが期待どおりに呼び出されたことを検討することができます。
101
101
102
-
Now the way we define the store might look a bit foreign to you.
102
+
今、ストアを定義する方法が、あなたには少し外に見えるかもしれません。
103
103
104
-
We’re using beforeEach to ensure we have a clean store before each test. beforeEach is a mocha hook that’s called before each test. In our test, we are reassigning the store variables value. If we didn’t do this, the mock functions would need to be automatically reset. It also lets us change the state in our tests, without it affecting later tests.
Great, so now we can mock actions, let’s look at mocking getters.
108
+
素晴らしい!今、アクションをモック化できるので、ゲッタのモックについて見ていきましょう。
109
109
110
-
## Mocking Getters
110
+
## ゲッタのモック
111
111
112
112
113
113
```html
@@ -130,9 +130,9 @@ export default{
130
130
</script>
131
131
```
132
132
133
-
This is a fairly simple component. It renders the result of the getters clicks and inputValue. Again, we don’t really care about what those getters returns – just that the result of them is being rendered correctly.
This test is similar to our actions test. We create a mock store before each test, pass it as an option when we call shallow, and assert that the value returned by our mock getters is being rendered.
175
174
176
-
This is great, but what if we want to check our getters are returning the correct part of our state?
[Modules](https://vuex.vuejs.org/en/modules.html) are useful for separating out our store into manageable chunks. They also export getters. We can use these in our tests.
0 commit comments