@@ -4,6 +4,7 @@ import VueRouter from 'vue-router'
44import { createLocalVue } from 'packages/test-utils/src'
55import Component from '~resources/components/component.vue'
66import ComponentWithVuex from '~resources/components/component-with-vuex.vue'
7+ import ComponentWithRouter from '~resources/components/component-with-router.vue'
78import ComponentWithSyncError from '~resources/components/component-with-sync-error.vue'
89import ComponentWithAsyncError from '~resources/components/component-with-async-error.vue'
910import { describeWithShallowAndMount , vueVersion } from '~resources/utils'
@@ -65,6 +66,37 @@ describeWithShallowAndMount('createLocalVue', mountingMethod => {
6566 expect ( typeof freshWrapper . vm . $route ) . toEqual ( 'undefined' )
6667 } )
6768
69+ it ( 'works with VueRouter' , async ( ) => {
70+ if ( mountingMethod . name === 'shallowMount' ) {
71+ return
72+ }
73+ const localVue = createLocalVue ( )
74+ localVue . use ( VueRouter )
75+ const Foo = {
76+ name : 'Foo' ,
77+ render : h => h ( 'span' , 'Foo component' )
78+ }
79+ const routes = [ { path : '/foo' , component : Foo } ]
80+ const router = new VueRouter ( {
81+ routes
82+ } )
83+ const wrapper = mountingMethod ( ComponentWithRouter , {
84+ localVue,
85+ router
86+ } )
87+
88+ expect ( wrapper . html ( ) ) . not . toContain ( 'Foo component' )
89+ expect ( wrapper . vm . $route ) . toBeTruthy ( )
90+
91+ await wrapper . vm . $router . push ( '/foo' )
92+ expect ( wrapper . html ( ) ) . toContain ( 'Foo component' )
93+
94+ await wrapper . vm . $router . push ( '/' )
95+ expect ( wrapper . html ( ) ) . not . toContain ( 'Foo component' )
96+ await wrapper . find ( 'a' ) . trigger ( 'click' )
97+ expect ( wrapper . html ( ) ) . toContain ( 'Foo component' )
98+ } )
99+
68100 it ( 'use can take additional arguments' , ( ) => {
69101 const localVue = createLocalVue ( )
70102 const pluginOptions = { foo : 'bar' }
0 commit comments