Vue routing Unit-Tests -?

Viewed 1158

I'm trying to unit-test: route-paths.

router/index.js (index.js is the file with the paths in the router folder)

import Vue from 'vue'
import Router from 'vue-router'
import Login00Z from '@/components/Login00Z'


Vue.use(Router)

export default new Router({
    mode:'history',
    routes: [
        { path: '/', name: 'default', component: Login00Z },
        { path: '/', redirect: {name: 'login00Z'} },
        { path: '/login00Z', name: 'login00Z', component: Login00Z }
    ]
})

specs/app.spec.js (app.spec.js is the file with the unit-tests in the specs folder)

import sinon from 'sinon'
import { expect } from 'chai'
import Vuetify from 'vuetify'
import { mount, shallowMount, createLocalVue } from '@vue/test-utils'
import VueRouter from 'vue-router'
import App from '@/App.vue'
import Login00Z from '@/components/Login00Z.vue'

describe('App.vue', () => {

    const localVue = createLocalVue()
    localVue.use(VueRouter)
    const router = new VueRouter()
    const wrapper = shallowMount(App, {
        Login00Z,
        localVue,
        router,
        stubs: ['v-navigation-drawer', 'v-list', 'v-list-tile',
         'v-list-tile-action', 'v-icon', 'v-list-tile-content',
         'v-list-tile-title', 'v-toolbar', 'v-toolbar-side-icon',
         'v-icon', 'v-toolbar-title', 'v-spacer', 'router-link',
         'router-view', 'v-app', 'v-btn','v-content',
         'v-slide-y-transition','v-layout', 'v-footer']
    })

    it('app loads with correct route', () => {
        expect(wrapper.vm.$route.path).to.equal('/')
    })

});

Okay, so let me explain:

As you can see there is one test that is made. The path should equal to (’/’), this does work, the test passes. When I write the exact same code and only change (’/’) to (’/login00Z’) the test fails. Now I knew that this wouldn’t work and I tried many different methods and I still can't figure out how to make this work.

Is there anyone who can help me out with testing(/mock) the ‘/login00Z’ path? I'm sure if I know how this is done, I can easily continue with my work.

0 Answers
Related