[Vuejs]-Import store in routes.js file cause error in jest (vuejs)

0👍

So, your Login.vue uses both router (this.$router.push({name: 'dashboard'})) and store (...mapActions('main', ['crud']),), but you give neither on the mount.

Maybe you should give it both:

import { mount, createLocalVue } from "@vue/test-utils"
import login from '@/pages/auth/login'
import Vuex from "vuex"
import VueRouter from "vue-router"

const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(VueRouter)


const store = new Vuex.Store({
  state: {
    // Your minimal default state here
  },
  actions: {
    // at least the 'main.crud' action, here
  }
})

const routes = [
  // Here minimal routes
]

const router = new VueRouter({ routes })

describe("login", () => {
    it("simple test", () => {
        const wrapper = mount(login, {
            router,
            store,
            localVue,
            data(){
                return {
                    form: {
                        mobile_number: '',
                    },
                }
            },
        })
        wrapper.find('#login').text()

    })
})

See here and here for more details.

Also, mapActions() should be in methods rather than data (See here)

Leave a comment