Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: (0 , _testUtils.createLocalVue) is not a function

This is my code. Can some please help me figure out the error.I am using jest to test out my frontend which I have built using Vue.The line const localVue = createLocalVue(); is giving out the error TypeError: (0 , _testUtils.createLocalVue) is not a function

import { createLocalVue,shallowMount  } from '@vue/test-utils'
import Vuex from 'vuex'
import getters from '../../src/store/module/auth/getters.js'
import TheHeader from '@/components/layout/TheHeader.vue'



// const store = new Vuex.Store({
//     state: {
//         user:null,
//         token:'',
//         expiresIn:null,
//         isUserLoggedIn:false,
//         isAdminLoggedIn:false,
//     }
//   })


describe('TheHeader', () => {
  const localVue = createLocalVue();
  localVue.use(Vuex);
  let store
  let state
 
  it('Checks whether the login is correctly displayed', () => {
    const cmp = shallowMount(TheHeader, { store,localVue})
    expect(cmp.name()).toMatch('TheHeader')
    expect(cmp.vm.isLoggedIn()).toBe(false)
  })

})

like image 789
doj Avatar asked Sep 19 '25 10:09

doj


1 Answers

createLocalVue was removed in version 2 of @vue/test-utils, which explains why it's undefined in your example.

  • To install a Vue plugin (such as Vuex), use the global.plugins mounting option

  • To mock instance APIs (such as this.$store), use the global.mocks mounting option

import Vuex from 'vuex'
import { shallowMount } from '@vue/test-utils'
import TheHeader from '@/components/TheHeader.vue'

const store = /* Vuex store */

const cmp = shallowMount(TheHeader, {
  global: {
    plugins: [Vuex],

    // OR:
    mocks: {
      $store: store,
    }
  }
})
like image 64
tony19 Avatar answered Sep 22 '25 05:09

tony19