davestewart / vuex-pathify

Vue / Vuex plugin providing a unified path syntax to Vuex stores
https://davestewart.github.io/vuex-pathify
MIT License
1.37k stars 57 forks source link

Error: [Vuex Pathify] Unexpected condition: this.$store is undefined. While running jest #146

Open adityaswaroop823 opened 1 year ago

adityaswaroop823 commented 1 year ago

I am trying to run my test case but getting this error =>

( throw new Error('[Vuex Pathify] Unexpected condition: this.$store is undefined.\n\nThis is a known edge case with some setups and will cause future lookups to fail') ^ Error: [Vuex Pathify] Unexpected condition: this.$store is undefined.)

this is my test Setup

import {
  mount,
  shallowMount,
  createLocalVue,
  RouterLinkStub
} from '@vue/test-utils'
import VueRouter from 'vue-router'
import mockRouter from './mockRouter'
import infiniteScroll from 'vue-infinite-scroll'
import Vuex from 'vuex'
import store from '../../src/state/index'
import '@/fontawesome'
import { i18n } from '@/i18n'
const router = mockRouter.mock()
global.wrap = (Component, options) => {
  const localVue = createLocalVue()
  localVue.use(VueRouter)
  localVue.use(infiniteScroll)
  localVue.use(Vuex)

  const wrapper = shallowMount(Component, {
    localVue,
    router,
    i18n,
    store
  })
  return wrapper
}

this is my test `import { shallowMount } from '@vue/test-utils'

import UpdateStatusModal from '../CircleMenu/UpdateStatusModal.vue'

describe('UpdateStatusModal', () => { it('should filter status codes for WORK', () => { const statusCodes = [ { Value: 'OPEN', text: 'Open' }, { Value: 'HOLD', text: 'Hold' }, { Value: 'CLOSE', text: 'Close' }, { Value: 'WORK', text: 'Work' }, { Value: 'RESOLVED', text: 'Resolved' } ]

const selectedStatusCode = 'WORK'

const wrapper = wrap(UpdateStatusModal, {
  propsData: {
    statusCodes,
    selectedStatusCode
  }
})

// Access the method from the Vue instance
const currentStatusCodes = wrapper.vm.currentStatusCodes()

const expectedResult = [
  { Value: null, text: 'Please select a status code' },
  { Value: 'WORK', text: 'Work' },
  { Value: 'RESOLVED', text: 'Resolved' }
]

expect(currentStatusCodes).toEqual(expectedResult)

})

it('should filter status codes for RESOLVED', () => { const statusCodes = [ { Value: 'OPEN', text: 'Open' }, { Value: 'HOLD', text: 'Hold' }, { Value: 'CLOSE', text: 'Close' }, { Value: 'WORK', text: 'Work' }, { Value: 'RESOLVED', text: 'Resolved' } ]

const selectedStatusCode = 'RESOLVED'

const wrapper = wrap(UpdateStatusModal, {
  propsData: {
    statusCodes,
    selectedStatusCode
  }
})

// Access the method from the Vue instance
const currentStatusCodes = wrapper.vm.currentStatusCodes()

const expectedResult = [
  { Value: null, text: 'Please select a status code' },
  { Value: 'OPEN', text: 'Open' },
  { Value: 'CLOSE', text: 'Close' },
  { Value: 'WORK', text: 'Work' }
]

expect(currentStatusCodes).toEqual(expectedResult)

})

it('should return all status codes by default', () => { const statusCodes = [ { Value: 'OPEN', text: 'Open' }, { Value: 'HOLD', text: 'Hold' }, { Value: 'CLOSE', text: 'Close' }, { Value: 'WORK', text: 'Work' }, { Value: 'RESOLVED', text: 'Resolved' } ]

const selectedStatusCode = 'OTHER'

const wrapper = shallowMount(UpdateStatusModal, {
  propsData: {
    statusCodes,
    selectedStatusCode
  }
})

// Access the method from the Vue instance
const currentStatusCodes = wrapper.vm.currentStatusCodes()

const expectedResult = [
  { Value: null, text: 'Please select a status code' },
  ...statusCodes
]

expect(currentStatusCodes).toEqual(expectedResult)

}) }) ` and this is my Component

`

` kindly help me regarding this issue.