Vue unit tests failing because component method calls this.$route.query - TypeError: Cannot read property 'query' of undefined
import import VueRouter from 'vue-router';
in your unite test file and create a new object of the router like const router = new VueRouter();
and use it in your test case.
I have updated code here:
import { shallowMount, createLocalVue } from '@vue/test-utils'import VueRouter from 'vue-router'import Articles from '../../../app/javascript/components/member-dashboard/Articles.vue'const localVue = createLocalVue()localVue.use(Vuex)localVue.use(VueRouter)localVue.use(BootstrapVue);const router = new VueRouter();describe('Articles', () => { let store let getters let state = { articles: [ { title: "Testing Vue Components" }, { title: "This One shows", text: "<p>You can see me!</p>" }, { title: "Another One", text: "<p>See me too!</p>" } ], userArticles: [ {article: { title: "This One shows", text: "<p>You can see me!</p>" }}, {article: { title: "Another One", text: "<p>See me too!</p>" }} ] } beforeEach(() => { getters = { articles: () => { return state.articles }, userArticles: () => { return state.userArticles } } store = new Vuex.Store({ getters }) }) it('only displays article with body text', () => { const wrapper = shallowMount(Articles, { store, router, localVue }) expect(wrapper.vm.articles.length).to.deep.equal(2) })})