I want to use a helper object/function in a Jest test with Vue test-utils, where I have a tests folder on my project root.
unitMocks.jsin tests/unit/unitMocks.js
export const mockComputed = {
products() {
return [1, 2, 3];
},
activities() {
return [4, 5, 6];
},
....
};
export const mockGetterProduct = () => {
...
Dashboard.spec.jsin tests/unit/views/
import Dashboard from "@/views/Dashboard.vue";
import { mockComputed } from "../unitMocks.js";
...
describe("Dashboard.vue", () => {
...
To import this, I want to avoid using a relative path (../unitMocks.js) so I was wondering how to access the relative root path.
I'm aware of the babel root import plugin and I also tried to modify the webpack alias of my vue.config.js:
module.exports = {
configureWebpack: {
resolve: {
alias: {
tests: "tests/"
}
}
},
...
..but my test still won't find that file when I import it.
Isn't there a native way of accessing the root path (like @ for src)? Is this related to Webpack or Babel?