반응형
chai 및 vue-test-utilities를 사용하여 Vue 구성 요소 테스트
내게는 버튼이 있는 컴포넌트가 있다.버튼을 클릭하면 Vuex 액션을 호출하고 API를 호출하여 데이터를 가져오고 스토어를 업데이트한다.
나는 이 기능을 테스트하고 싶다.나는 Vue에서의 시험을 처음 본다.
import { shallowMount, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import store from '../../src/store'
import flushPromises from 'flush-promises'
import { assert } from 'chai';
const localVue = createLocalVue()
localVue.use(Vuex)
import SomeComponent from '../../src/templates/views/SomeComponent'
describe('test', () => {
it('test', async () => {
const wrapper = shallowMount(SomeComponent, { store, localVue })
wrapper.find('button').trigger('click')
await flushPromises()
console.log(store.state.users.length)
})
})
API 호출이 완료되지 않아 0으로 기록된다.이 문제를 해결하기 위한 아이디어를 제안하는 사람이 있다면 도움이 될 것이다.
참조URL: https://stackoverflow.com/questions/58683444/testing-vue-component-with-chai-and-vue-test-utils
반응형
'programing' 카테고리의 다른 글
C/C++ 프로그램과 그 플러그 인 DLL을 위한 최고의 무료 메모리 누수 검출기는 무엇인가? (0) | 2022.05.15 |
---|---|
Vue 플러그인 설치 기능에 Vuex를 추가하고 구성 요소 간에 상태를 공유하는 방법이 있는가? (0) | 2022.05.15 |
16진수 문자열(char [])을 int로 변환하시겠습니까? (0) | 2022.05.15 |
64비트 Windows에서 긴 비트 크기 (0) | 2022.05.15 |
동적으로 생성된 구성 요소의 vuex 저장소 분리 (0) | 2022.05.15 |