質問編集履歴
1
テストコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -110,6 +110,46 @@
|
|
110
110
|
|
111
111
|
```
|
112
112
|
|
113
|
+
smaple.spec (テスト)
|
114
|
+
```js
|
115
|
+
import { shallowMount, createLocalVue } from '@vue/test-utils'
|
116
|
+
import Vuex from 'vuex'
|
117
|
+
import registrationBtn from '@/components/BookPostKit/button/registrationBtn.vue'
|
118
|
+
|
119
|
+
const localVue = createLocalVue()
|
120
|
+
|
121
|
+
localVue.use(Vuex)
|
122
|
+
|
123
|
+
describe('Actions.vue', () => {
|
124
|
+
let actions
|
125
|
+
let store
|
126
|
+
let mutations
|
127
|
+
|
128
|
+
beforeEach(() => {
|
129
|
+
actions = {
|
130
|
+
post: jest.fn()
|
131
|
+
}
|
132
|
+
|
133
|
+
mutations = {
|
134
|
+
selectedBook: () => {},
|
135
|
+
disabled: () => {}
|
136
|
+
}
|
137
|
+
|
138
|
+
store = new Vuex.Store({
|
139
|
+
state: {},
|
140
|
+
mutations,
|
141
|
+
actions
|
142
|
+
})
|
143
|
+
})
|
144
|
+
|
145
|
+
it('アクションテスト', () => {
|
146
|
+
const wrapper = shallowMount(registrationBtn, { store, localVue })
|
147
|
+
wrapper.find('button').trigger('click')
|
148
|
+
expect(actions.post).toHaveBeenCalled()
|
149
|
+
})
|
150
|
+
})
|
151
|
+
|
152
|
+
```
|
113
153
|
|
114
154
|
### 試したこと
|
115
155
|
・mutationsのモックが作成されていない事で起こるエラーかと思い、selectedBookとdisabledのモックを追加しました。
|