C
C
Comnox2021-07-12 20:26:28
Vue.js
Comnox, 2021-07-12 20:26:28

When testing Vue 3 with Jest, "Cannot read property 'getters' of undefined" error?

Hello everyone, I've encountered such a problem that when testing, an error appears "Cannot read property 'getters' of undefined" and [Vue warn]: Property "$store" was accessed during render but is not defined on instance.
although I don’t seem to use getters in the test:

60ec7b362adf7791717997.png

the code of the test itself:

import { mount } from "@vue/test-utils";
import Cards from "@/components/Cards.vue";

describe("Cards", () => {
  it("init test for Cards", () => {
    const wrapper = mount(Cards);
    expect(wrapper.contains("div")).toBeTruthy();
  });
});


in other components where store is not used, everything works correctly, so I thought that perhaps there was an error due to import, but everything seems to be correct, main.js settings:
import { createApp } from "vue";
import App from "@/App.vue";
import router from "@/router";
import store from "@/store";

createApp(App).use(store).use(router).mount("#app");

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question