programing

VueJS에서 테스트를 실행할 때 오류 발생: 경로 탐색 중 검색되지 않은 오류

prostudy 2022. 4. 19. 19:06
반응형

VueJS에서 테스트를 실행할 때 오류 발생: 경로 탐색 중 검색되지 않은 오류

템플릿에 라우터 구성 요소가 있을 때마다 장치 테스트에서 이 경고가 계속 표시됨:

수 없는 사용자 정의 요소 이전에 이 문제에 대한 티켓을 한 장 올렸으며, 같은 시도를 했지만 운이 따르지 않았다.이 오류에 대해 좀 더 알고 있는 사람이 있을까?

FinalCountdown.html

<div id="c-final-countdown">
  <h1>Hello App!</h1>
  <p>
    <!-- use router-link component for navigation. -->
    <!-- specify the link by passing the `to` prop. -->
    <!-- <router-link> will be rendered as an `<a>` tag by default -->
    <router-link to="/foo">Go to Foo</router-link>
    <router-link to="/bar">Go to Bar</router-link>
  </p>
</div>

FinalCountdown.spec.js

import Vue from 'vue'
import router from '../../router'
import FinalCountdown from 'src/components/workflow/FinalCountdown'

describe('workflow/FinalCoundDown component.'), () => {
  const getComponent = (date) => {
    let vm = new Vue({
      template: '<div><final-countdown ref="component"></final-countdown></div>',
      components: {
        FinalCountdown
      }
    })
    return vm
  }

  it('Should render correctly with a date in the future.', () => {
    const tomorrow = new Date(new Date().getTime() + 24 * 60 * 60 * 1000)
    const vm = getComponent().$mount()
    const component = vm.$refs.component

    expect(vm.$el).toBeTruthy()
    console.log(vm.$el) // <div><!----></div>
  })
}

우리의 주장은 우리가 제공해야만 하기 때문에 실패한다.vm을 예로 들다.VueRouter인스턴스그래서 그때getComponent다음이 됨:

  const getComponent = (date) => {
    Vue.use(vueRouter)
    const routes = { ... };
    const router = new VueRouter({ routes })
    let vm = new Vue({
      router,
      template: '<div><final-countdown ref="component"></final-countdown></div>',
      components: {
        FinalCountdown
      }
    })
    return vm
  }

그리고 나서 부품 마운팅을 볼 수 있는데 경고 오류가 발생했어.모든 것이 이치에 맞기를 바란다:d

WARN LOG: '[vue-router] uncaught error during route navigation:'

참조URL: https://stackoverflow.com/questions/44564812/error-when-running-tests-in-vuejs-vue-router-uncaught-error-during-route-naviga

반응형