1
vue 라우터를 사용하여 $ route를 보는 단일 파일 구성 요소를 테스트하고 있습니다. 문제는 경로를 변경하고 감시자의 기능을 트리거하는 테스트를받을 수 없다는 것입니다.
테스트 파일 :
이import { createLocalVue, shallow } from 'vue-test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
const localVue = createLocalVue();
localVue.use(Vuex);
const $route = {
path: '/my/path',
query: { uuid: 'abc' },
}
wrapper = shallow({
localVue,
store,
mocks: {
$route,
}
});
it('should call action when route changes',() => {
// ensure jest has a clean state for this mocked func
expect(actions['myVuexAction']).not.toHaveBeenCalled();
vm.$set($route.query, 'uuid', 'def');
//vm.$router.replace(/my/path?uuid=def') // tried when installing actual router
//vm.$route.query.uuid = 'def'; // tried
//vm.$route = { query: { uuid: 'def'} }; // tried
expect(actions['myVuexAction']).toHaveBeenLastCalledWith({ key: true });
});
SFC에서 내 시계 방법 : 당신이 그것을보고 시계 방법을 테스트 할 수있는 방법으로 모의 라우터를 어떻게
watch: {
$route() {
this.myVuexAction({ key: true });
},
},
을하고있다 네가 예상대로?