VueRouter is undefined in karma unit tests VueRouter is undefined in karma unit tests vue.js vue.js

VueRouter is undefined in karma unit tests


It looks like your routes might not be set up anywhere in your test environment. If you're using Karma and Avoriaz or Vue Test Utils, I've been able to test components that contain routes like this:

import { mount } from 'vue-test-utils'import router from 'src/router' // path to your routerimport MyComponent from 'src/components/MyComponent'describe('MyComponent.vue', () => {  let wrapper  beforeEach(() => {    wrapper = mount(MyComponent, {      router: router    })  })  it('has a created hook', () => {    expect(typeof wrapper.created).to.equal('function')  })  ...})