반응형
테스트 스위트에서 Jest + Nuxt + Nuxt-Fire가 실패함
Nuxt와 Nuxt-Fire를 함께 사용하고 있습니다(https://github.com/lupas/nuxt-fire)
테스트를 시작할 때 이 오류가 표시됩니다.[Vue warn]: Error in config.errorHandler: "TypeError: Cannot read property 'ref' of undefined"
이 문제는 내 앱의 이 섹션 때문에 발생합니다.
mounted() {
this.initiate(window.instaroomId)
let connected = this.$fireDb.ref(".info/connected")
this.getConnection(connected)
},
이렇게 생겼어요.$fireDb는 호출되지 않습니다.모듈은 보통 nuxt.config.js에 로드됩니다.어떻게 하면 될까요?
테스트하고 싶은 경우this.$fireDb.ref(".info/connected")이렇게 조롱할 수 있다고 합니다.
import { shallowMount } from '@vue/test-utils'
import SomeComponent from '@/components/SomeComponent/SomeComponent.vue'
let wrapper
describe('SomeComponent.vue Test', () => {
beforeEach(() => {
wrapper = shallowMount(SomeComponent, {
mocks: {
$fireDb: {
ref: jest.fn()
}
}
})
})
it('$fireDb.ref was called', () => {
expect(wrapper.vm.$fireDb.ref).toBeCalled()
expect(wrapper.vm.$fireDb.ref).toBeCalledWith('.info/connected')
})
})
시험을 통과하고 싶다면created()시뮬레이션만 할 수 있는 다른 기능을 후크하여 테스트합니다.$fireDb.ref테스트도 안 해봤어요
언급URL : https://stackoverflow.com/questions/53885177/jest-nuxt-nuxt-fire-is-failing-in-test-suite
반응형
'programing' 카테고리의 다른 글
| scanf()를 사용하여 문자열 크기를 초과하면 안 됩니다. (0) | 2022.08.23 |
|---|---|
| 서버에서 Vuex + Vue 풀 상태를 1회만 실행 (0) | 2022.08.23 |
| 시계열 스트림, x축 및 24시간 형식에서 am/pm 제거 (0) | 2022.08.23 |
| Vuex - 동작에만 돌연변이 노출 (0) | 2022.08.23 |
| vue 구성 요소에서 vuex 모듈의 상태, getter 및 작업을 가져오는 중 (0) | 2022.08.16 |