반응형
TypeError로 인해 Vuex+Jest 테스트가 실패함
응용 프로그램에서 Vuex 스토어 모듈을 테스트하려고 하는데 계속 반환됨TypeError: Cannot read property 'getters' of undefined
무슨 수를 써서라도제발 도와주세요.암호는 다음과 같다.
store/index.ts:
import Vuex from 'vuex';
import auth from './auth';
Vue.use(Vuex);
export default new Vuex.Store({
state: {},
mutations: {},
actions: {},
modules: {
auth,
},
});
store/auth.ts:
export default {
state: {
isLoggedIn: getKey(),
},
namespaced: true,
mutations: {
setLoginState(state: any, isLoggedIn: boolean) {
state.isLoggedIn = isLoggedIn;
},
},
actions: {
// Stuff
},
};
store/__built__/auth.ts:
import auth from '../auth';
describe('Auth.ts', () => {
describe('Mutations', () => {
test('setLoginState sets isLoggedIn correctly', () => {
const state = {
isLoggedIn: false,
};
auth.mutations.setLoginState(state, true);
expect(state.isLoggedIn).toBe(true);
});
});
});
사용된 패키지:
"vue": "^2.5.22",
"vuex": "^3.1.0",
"webpack": "^4.29.0"
"jest": "^23.6.0",
"ts-jest": "^23.10.5",
나는 문제를 발견했다.문제는 auth.ts가 axios 인스턴스를 가져오고 있었다는 것인데, 이것은 조롱되지 않았다.공리 호출이 필요한 작업 제거 또는 추가jest.mock('API_PATH', jest.fn);
테스트하여 문제를 해결하십시오.
참조URL: https://stackoverflow.com/questions/54299519/vuexjest-test-fails-with-typeerror
반응형
'programing' 카테고리의 다른 글
C의 크기가 "int"가 2바이트인가 4바이트인가? (0) | 2022.05.26 |
---|---|
분할("|")을 사용하여 파이프 기호를 기준으로 Java 문자열 분할 (0) | 2022.05.26 |
형식 지정 구성 요소에서 Vue 프로토타입 속성에 액세스하는 방법 (0) | 2022.05.25 |
vue2는 구성 요소의 $properties를 사용하여 상위 함수를 호출함 (0) | 2022.05.25 |
http 요청을 사용하여 Vue 양식 입력을 Adonis 컨트롤러로 보내는 방법 (0) | 2022.05.25 |