Skip to content

injection "store" not found #407

@techlab23

Description

@techlab23

Hello,

I'm trying to setup tests for the component using mock vuex store, however i'm running into an issue where i get the following warning and subsequent error in setup function of the component.

Here is the sample component that i used to reproduce this issue

https://github.com/techlab23/task-management-app-ts/blob/tests/tests/App.spec.ts

      [Vue warn]: injection "store" not found. 
        at <Anonymous ref="VTU_COMPONENT" > 
        at <VTUROOT>

      16 |   components: { AppHeader, AppLoadingIndicator },
      17 |   setup() {
    > 18 |     const store = useStore();
         |                   ^
      19 |     store.dispatch('fetchData');
      20 |     const isLoading = computed<boolean>(() => store.getters.isLoading);
      21 |     return {

Following above error i get another error in calling a dispatch function


App › calls fetchData to load initial data

    TypeError: Cannot read property 'dispatch' of undefined

      17 |   setup() {
      18 |     const store = useStore();
    > 19 |     store.dispatch('fetchData');
         |           ^
      20 |     const isLoading = computed<boolean>(() => store.getters.isLoading);
      21 |     return {
      22 |       isLoading,

      at setup (src/App.vue:19:11)

Appreciate any pointers is resolving this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions