Vuejs2 如何在路由更新导航卫士之前测试vue路由器?

Vuejs2 如何在路由更新导航卫士之前测试vue路由器?,vuejs2,jestjs,vue-router,vue-test-utils,Vuejs2,Jestjs,Vue Router,Vue Test Utils,首先,我使用的是Vue属性装饰器。 我的组件有一个组件路由,定义如下 @Component({ components: { ComponentA, ComponentB }, beforeRouteUpdate (to, _from, next) { const { checkInDate, checkOutDate, items, currency, locale } = to.query; const queryFullfilled = !!che

首先,我使用的是Vue属性装饰器。 我的组件有一个组件路由,定义如下

@Component({
  components: {
    ComponentA,
    ComponentB
  },
  beforeRouteUpdate (to, _from, next) {
    const { checkInDate, checkOutDate, items, currency, locale } = to.query;
    const queryFullfilled = !!checkInDate && !!checkOutDate && !!items.length && !!currency && !!locale;

    if ([BOOKING_PAGE, RESERVATION_PAGE].indexOf(to.name) > -1 && queryFullfilled) {
      this.validateRooms();
    }
    next();
  }
})
export default class Layout extends Vue {}
我需要在我的规格中做些什么,以涵盖在常规更新之前发生的事情?我已经在谷歌上搜索过了,人们都指向调用
wrapper.vm.$options.beforeRouteUpdate.call()
。。。那对我不起作用

以前有人这样做过吗?有我可以看的代码示例吗

提前谢谢。
John。

如果有人仍在寻找答案,以下代码将起作用

const beforeRouteUpdate = wrapper.vm.$options.beforeRouteUpdate[0];
let nextFun = jest.fn();

// in place wrapper.vm you can send any object you want bcz when we call beforeRouteUpdate it looses this context

beforeRouteUpdate.call(wrapper.vm , "toObj", "fromObj", nextFun); 

如果任何人仍在寻找答案,以下代码将起作用

const beforeRouteUpdate = wrapper.vm.$options.beforeRouteUpdate[0];
let nextFun = jest.fn();

// in place wrapper.vm you can send any object you want bcz when we call beforeRouteUpdate it looses this context

beforeRouteUpdate.call(wrapper.vm , "toObj", "fromObj", nextFun); 

可以通过组件类访问route guard。传入实例的
vm
,这样您就可以访问
this


可以通过组件类访问route guard。传入实例的
vm
,这样您就可以访问
this

控制台如何记录您正在处理的任何数据,如果需要,添加另一个路由生命周期事件并记录到那里compare@Michael. 我知道beforeRouteUpdate是有效的,因为当我在浏览器中加载组件时,我会得到预期的结果。我从视觉上看到了它。我的问题更多的是如何在单元测试中测试它。在我的单元测试中,如何在RouteUpdate之前触发?控制台如何记录您正在处理的任何数据,如果需要,添加另一个route生命周期事件并记录到其中compare@Michael. 我知道beforeRouteUpdate是有效的,因为当我在浏览器中加载组件时,我会得到预期的结果。我从视觉上看到了它。我的问题更多的是如何在单元测试中测试它。在我的单元测试中,如何在路由更新之前触发?