单击使用$ router.push的孩子时测试Vue Router

问题描述

一旦触发click事件并调用$ router.push(),我想测试路由器是否正常工作。 我的组件看起来像这样

<h6 class="text-center projektt-grey">
  Already have an account?
  <span ref="signInBtn" @click="$router.push('/auth/signin')" class="text-primary"
    >Sign in.</span
  >
</h6>

然后在测试中,使用ref这样单击按钮(跨度):

  it("redirects the user to the SignIn page",async () => {
    const wrapper = mount(Auth,{
      store: storeMocks.store,localVue,router
    });

    const buttonWrapper = wrapper.find({ref: 'signInBtn'});
    buttonWrapper.trigger('click');

    await Vue.nextTick();

    console.log(wrapper.vm.$route.fullPath)
    expect(wrapper.vm.$route.fullPath).toBe('/auth/signin');
  })

我希望发生的事情是调用@click处理程序,将$ route.fullPath更改为“ / auth / signin”,但是得到的是“ /” 我尝试模拟$ route和$ router,并期望使用'/ auth / signin'调用$ router.push(),但是再次失败,说根本没有调用

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)