-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot find module './src/components/Message' from 'MessageToggle.vue' #5
Comments
Yeah this seems to be blocking me from adopting Jest. |
You can use aliases in Jest. Checkout this Jest config, it maps https://github.com/vuejs/vue-test-utils-jest-example/blob/master/package.json#L39 More info — https://facebook.github.io/jest/docs/en/configuration.html#modulenamemapper-object-string-string |
It doesn't work for me. My "moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
} You can reproduce within this repository, just change It resolves to |
That's strange, it works correctly for me in the vue-test-utils-jest-example. What are your details (OS, node version, npm version) |
I have the same problem. |
Node 9.2.1 |
@freakyfanny with a clean install? |
yes |
I migrated my project to a more recent I can now import with the |
I can 2 now. 😀thanks anyway
Med vänlig hälsning
Fanny Petersson Sällberg
… On 18 Dec 2017, at 21:07, Thomas Sauvajon ***@***.***> wrote:
I migrated my project to a more recent vue-cli webpack template, due to 2 issues (the current one and this one with vue-jest).
I can now import with the @ alias without problem.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Had a similar issue as I was using // jest.config.js
module.exports = {
moduleFileExtensions: ['js', 'json', 'vue'],
moduleDirectories: ['node_modules'],
setupTestFrameworkScriptFile: 'mock-local-storage',
moduleNameMapper: {
'^.+\\.(jpg|jpeg)$': 'jest-static-stubs/jpg',
'^.+\\.(png)$': 'jest-static-stubs/png',
'^.+\\.(svg)$': 'identity-obj-proxy',
'@/(.*)': '<rootDir>/client/$1',
'~/(.*)': '<rootDir>/client/$1',
},
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest',
},
setupFiles: ['./client/plugins/components.js'],
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
}; .babelrc {
"env": {
"test": {
"presets": ["env"],
"plugins": [
"transform-es2015-modules-commonjs",
"transform-object-rest-spread",
"dynamic-import-node",
[
"module-resolver",
{
"root": ["./"],
"alias": {
"@": "./client/",
"~": "./client/"
}
}
]
]
}
}
} Removing the {
"env": {
"test": {
"presets": ["env"],
"plugins": [
"transform-es2015-modules-commonjs",
"transform-object-rest-spread",
"dynamic-import-node",
]
}
}
} |
If I use an alias to resolve my components path e.g.
import Message from '@/components/Message'
instead ofimport Message from ./Message
, my tests fail.I can temporarly use relative paths instead of
@/
, but using aliases is extremely convenient for me and my team ...The text was updated successfully, but these errors were encountered: