source

Vue.js 장치 테스트 중 vuex 저장소 업데이트 오류

nicesource 2023. 7. 8. 10:59
반응형

Vue.js 장치 테스트 중 vuex 저장소 업데이트 오류

테스트에서 커밋을 사용하여 vuex 상태 값을 변경한 다음 변경 사항에 따라 렌더링되어야 하는 요소가 있는지 확인하려고 합니다.이런 거.

it('should render error state if no stores', () => {
    wrapper.store.commit('stores/updateLoadingStores', false);
    wrapper.store.commit('stores/updateStores', []);
    expect(wrapper.find('error-state-stub').exists()).toBe(true);
});

대신 다음 오류가 발생합니다. '''StoresStep » 스토어가 없으면 오류 상태를 렌더링해야 합니다.

TypeError: Cannot read property '_isDestroyed' of undefined

  31 |     const mutationName = `${prefix}${_upperFirst(name)}`;
  32 |     acc[mutationName] = (state, value) => {
> 33 |       state[name] = value;
     |       ^
  34 |     };
  35 |     return acc;
  36 |   }, {});

  at destroy (node_modules/vue/dist/vue.runtime.common.dev.js:3151:28)
  at invokeDestroyHook (node_modules/vue/dist/vue.runtime.common.dev.js:6088:59)
 ...
```

이것이 불평하는 기능은 특정 모듈에 값을 설정하기 위한 래퍼입니다.실제 오류 참조 -TypeError: Cannot read property '_isDestroyed' of undefined에서 오는vue.runtime.common.dev.js

부에인 줄 알았어요.$nextTick() 관련이 있지만 아닌 것 같습니다.

wrapper.store부품은 부품을 장착하고 관련된 모든 것을 한 곳에서 사용할 수 있도록 작성한 유틸리티입니다.

도움을 주시면 감사하겠습니다.

마침내 저는 그것을 알아냈습니다.그 문제는 명백하지 않았습니다.저는 원래의 문제에 대한 단서를 찾기 위해 vue.js 소스 코드를 조사해야 했습니다.기본적으로, 이 vue-test-sys 문제는 부분적으로 그것을 설명합니다 - https://github.com/vuejs/vue-test-utils/issues/52

가장 큰 문제는 오류가 당신을 과도기로 연결시키지 않는다는 것이었습니다. 그래서 저는 잘못된 방향을 보고 있었습니다.

그리고 솔루션은 단순하고, 단순한 전환입니다 :)

VueTestUtils.config.stubs['transition'] = true;

언급URL : https://stackoverflow.com/questions/57189442/vue-js-unit-testing-updating-vuex-store-error

반응형