Vue.js test unit imports failing in spec files

320 Views Asked by At

from a demo project, I can see that :

src
    components
        ShoppingList.spec.js
        ShoppingList.vue
    store
        __mocks__
            index.js
        index.js


ShoppingList.spec.js
    import { __creareMocks as createMocks } from "../store";
    ...
    jest.mock("../store");

this run without any problem, both imports are correct

========

I am trying to use it, but in my own project structure

src
    components
        ContactForm.vue
    store
        index.js
tests
    unit
        store
            __mocks__
                index.js
        ContactForm.spec.js

ContactForm.spec.js
    import { __creareMocks as createMocks } from "../store";
    ...
    jest.mock("../store");

both import are failing with Cannot find module '../store' from 'ContactForm.spec.js' error

1

There are 1 best solutions below

0
AudioBubble On

THe correct structure

src
    components
        ContactForm.vue
    store
        __mocks__
            index.js
        index.js
tests
    unit
        ContactForm.spec.js

ContactForm.spec.js
    import { __creareMocks as createMocks } from "@/store";
    ...
    jest.mock("@/store");