質問編集履歴
7
コード例の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
|
41
41
|
localVue.use(Vuex)
|
42
42
|
|
43
|
-
const obj = {
|
43
|
+
const obj = { title: 'test-title' }
|
44
44
|
|
45
45
|
getters = { ...mapGetters(['path/path', {data: () => obj } as any]) }
|
46
46
|
|
@@ -106,11 +106,11 @@
|
|
106
106
|
|
107
107
|
head(): MetaInfo {
|
108
108
|
|
109
|
-
const {
|
109
|
+
const {title} = this.data
|
110
110
|
|
111
111
|
return {
|
112
112
|
|
113
|
-
title:
|
113
|
+
title: title
|
114
114
|
|
115
115
|
}
|
116
116
|
|
@@ -168,7 +168,7 @@
|
|
168
168
|
|
169
169
|
localVue.use(Vuex)
|
170
170
|
|
171
|
-
const obj = {
|
171
|
+
const obj = { title: 'test-title' }
|
172
172
|
|
173
173
|
|
174
174
|
|
@@ -228,7 +228,7 @@
|
|
228
228
|
|
229
229
|
Expected: "test-title" │
|
230
230
|
|
231
|
-
Received: "
|
231
|
+
Received: "undefined"
|
232
232
|
|
233
233
|
```
|
234
234
|
|
6
コメントの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -174,6 +174,8 @@
|
|
174
174
|
|
175
175
|
wrapper = mount(Component, {
|
176
176
|
|
177
|
+
// mockで$storeを設定
|
178
|
+
|
177
179
|
mocks: {
|
178
180
|
|
179
181
|
$store: {
|
5
エラー解決の追記(回答受付中)
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,8 +26,6 @@
|
|
26
26
|
|
27
27
|
const localVue = createLocalVue()
|
28
28
|
|
29
|
-
const id = 'test-id'
|
30
|
-
|
31
29
|
|
32
30
|
|
33
31
|
let wrapper: any
|
@@ -137,3 +135,99 @@
|
|
137
135
|
```
|
138
136
|
|
139
137
|
上記のようなエラーが発生してしまいます。こちらどのようにすればエラーを解決できるか教えていただきたく投稿させていただきました。よろしくお願いいたします。
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
追記
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
import Component from '@/pages/component'
|
148
|
+
|
149
|
+
import { createLocalVue, mount } from '@vue/test-utils'
|
150
|
+
|
151
|
+
import VueMeta from 'vue-meta'
|
152
|
+
|
153
|
+
import Vuex, { mapGetters } from 'vuex'
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
describe('test', () => {
|
158
|
+
|
159
|
+
const localVue = createLocalVue()
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
let wrapper: any
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
beforeEach(() => {
|
168
|
+
|
169
|
+
localVue.use(Vuex)
|
170
|
+
|
171
|
+
const obj = { name: 'test-title' }
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
wrapper = mount(Component, {
|
176
|
+
|
177
|
+
mocks: {
|
178
|
+
|
179
|
+
$store: {
|
180
|
+
|
181
|
+
getters: {
|
182
|
+
|
183
|
+
...mapGetters(['path/path', { data: () => obj } as any]),
|
184
|
+
|
185
|
+
},
|
186
|
+
|
187
|
+
},
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
)
|
192
|
+
|
193
|
+
})
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
afterEach(() => {
|
198
|
+
|
199
|
+
if (wrapper) {
|
200
|
+
|
201
|
+
wrapper.destroy()
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
})
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
it('should have head title', () => {
|
210
|
+
|
211
|
+
localVue.use(VueMeta, { keyName: 'head' })
|
212
|
+
|
213
|
+
expect(wrapper.vm.$metaInfo.title).toBe('test-title')
|
214
|
+
|
215
|
+
})
|
216
|
+
|
217
|
+
```
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
上記のような形でエラーは解消できました!ただ、テストの結果が
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
```
|
226
|
+
|
227
|
+
Expected: "test-title" │
|
228
|
+
|
229
|
+
Received: "mappedGetter"
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
となってしまいます。こちらわかる方いましたらご回答お願いいたします。
|
4
不要な記述の削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,21 +50,7 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
wrapper = mount(Component, {
|
53
|
+
wrapper = mount(Component, {store})
|
54
|
-
|
55
|
-
mocks: {
|
56
|
-
|
57
|
-
$route: {
|
58
|
-
|
59
|
-
params: { id },
|
60
|
-
|
61
|
-
},
|
62
|
-
|
63
|
-
},
|
64
|
-
|
65
|
-
store,
|
66
|
-
|
67
|
-
})
|
68
54
|
|
69
55
|
})
|
70
56
|
|
3
誤字の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
const obj = { name: 'test-title' }
|
46
46
|
|
47
|
-
getters = { ...mapGetters(['path/path', {
|
47
|
+
getters = { ...mapGetters(['path/path', {data: () => obj } as any]) }
|
48
48
|
|
49
49
|
store = new Vuex.Store({ getters })
|
50
50
|
|
2
誤字の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
import { createLocalVue, mount } from '@vue/test-utils'
|
18
18
|
|
19
|
-
import VueMeta from 've-meta'
|
19
|
+
import VueMeta from 'vue-meta'
|
20
20
|
|
21
21
|
import Vuex, { mapGetters } from 'vuex'
|
22
22
|
|
1
誤字の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -151,157 +151,3 @@
|
|
151
151
|
```
|
152
152
|
|
153
153
|
上記のようなエラーが発生してしまいます。こちらどのようにすればエラーを解決できるか教えていただきたく投稿させていただきました。よろしくお願いいたします。
|
154
|
-
|
155
|
-
nuxt.jsでユニットテストを作成しています。
|
156
|
-
|
157
|
-
https://stackoverflow.com/questions/59964001/how-to-test-head-in-nuxt-js-using-jest
|
158
|
-
|
159
|
-
こちらの記事を参考にvue-metaのhead()のテストを書いてみました。
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
```
|
164
|
-
|
165
|
-
// sample.spec.ts
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
import Component from '@/pages/component'
|
170
|
-
|
171
|
-
import { createLocalVue, mount } from '@vue/test-utils'
|
172
|
-
|
173
|
-
import VueMeta from 'vue-meta'
|
174
|
-
|
175
|
-
import Vuex, { mapGetters } from 'vuex'
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
describe('test', () => {
|
180
|
-
|
181
|
-
const localVue = createLocalVue()
|
182
|
-
|
183
|
-
const id = 'test-id'
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
let wrapper: any
|
188
|
-
|
189
|
-
let getters: any
|
190
|
-
|
191
|
-
let store: any
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
beforeEach(() => {
|
196
|
-
|
197
|
-
localVue.use(Vuex)
|
198
|
-
|
199
|
-
const obj = { name: 'test-title' }
|
200
|
-
|
201
|
-
getters = { ...mapGetters(['path/path', { detail: () => obj } as any]) }
|
202
|
-
|
203
|
-
store = new Vuex.Store({ getters })
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
wrapper = mount(Component, {
|
208
|
-
|
209
|
-
mocks: {
|
210
|
-
|
211
|
-
$route: {
|
212
|
-
|
213
|
-
params: { id },
|
214
|
-
|
215
|
-
},
|
216
|
-
|
217
|
-
},
|
218
|
-
|
219
|
-
store,
|
220
|
-
|
221
|
-
})
|
222
|
-
|
223
|
-
})
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
afterEach(() => {
|
228
|
-
|
229
|
-
if (wrapper) {
|
230
|
-
|
231
|
-
wrapper.destroy()
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
})
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
it('should have head title', () => {
|
240
|
-
|
241
|
-
localVue.use(VueMeta, { keyName: 'head' })
|
242
|
-
|
243
|
-
expect(wrapper.vm.$metaInfo.title).toBe('test-title')
|
244
|
-
|
245
|
-
})
|
246
|
-
|
247
|
-
```
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
```
|
252
|
-
|
253
|
-
// sample.vue
|
254
|
-
|
255
|
-
<template>
|
256
|
-
|
257
|
-
<div></div>
|
258
|
-
|
259
|
-
</template>
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
<script lang="ts">
|
264
|
-
|
265
|
-
import { Component, Getter, Vue } from 'nuxt-property-decorator'
|
266
|
-
|
267
|
-
import type { MetaInfo } from 'vue-meta'
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
@Component
|
272
|
-
|
273
|
-
export default class Component extends Vue {
|
274
|
-
|
275
|
-
@Getter('path/path') data!: any
|
276
|
-
|
277
|
-
head(): MetaInfo {
|
278
|
-
|
279
|
-
const {name} = this.data
|
280
|
-
|
281
|
-
return {
|
282
|
-
|
283
|
-
title: name
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
</script>
|
292
|
-
|
293
|
-
```
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
- 発生しているエラー
|
298
|
-
|
299
|
-
```
|
300
|
-
|
301
|
-
[Vue warn]: Error in getter for watcher "$metaInfo": "TypeError: Cannot read properties of undefined (reading '$store')"
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
```
|
306
|
-
|
307
|
-
上記のようなエラーが発生してしまいます。こちらどのようにすればエラーを解決できるか教えていただきたく投稿させていただきました。よろしくお願いいたします。
|