-
Notifications
You must be signed in to change notification settings - Fork 157
Failed parse using external template #45
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
Comments
What's the absolute path of simplert.html? |
It's coming from other npm repository, so should be coming from |
Does this resolve correctly when you use vue-loader? |
Sure, working like charm... |
This is a problem on our side we need to fix. At the moment, we only look for a src that is relative, not in node_modules Thanks for bring it to my attention, I'll look to get a fix in place 🙂 |
I'm using relative templates but I still have an issue. The templates do get parsed, but I think they're not "interpreted" correctly. Repro: https://github.com/laggingreflex/repro-vue-jest-template It works in the browser but running jest it gives this error
Taking hint from the error, if I change my <template>
<div>App</div>
</template> to just <div>App</div> the test passes, but that's not the correct format for template - the app doesn't work in the browser. |
@laggingreflex can you open a new issue for this so that I can track it? |
@eddyerburgh please check my PR and let me know what do you think 🤞 // TestComponent.spec.js import { mount } from '@vue/test-utils' import MyComponent from './MyComponent.vue' describe('Sample test', () => { it('...', () => { const wrapper = mount(MyComponent) expect(...) }) ... }) // MyComponent.vue <template src="@node/dependency/src/MyComponent.html"/> <script src="@node/dependency/src/MyComponent.js"/> // jest.config.js module.exports = { 'moduleNameMapper': { '^@node/dependency/(.*)$': '/node_modules/@node/dependency/$1', '^vue$': 'vue/dist/vue.common.js' }, 'moduleFileExtensions': [ 'js', 'vue' ], 'transform': { '^.+\\.js$': '/node_modules/babel-jest', '.*\\.vue$': '/node_modules/vue-jest' }, 'transformIgnorePatterns': ['/node_modules/dependency/node_modules'] } |
Hello guys. We have a project that is in a similar situation.
As we can see, each alias is a reference to the "src" directory. And this is how we use them in vue files:
OK, to use Jest we need to replicate the above case in a configuration. This is how it looks:
And the result after the transformation from "vue-jest" is: Which is absolutely logical, judging by these lines of code in "vue-jest/lib/process":
To the authors: You need to rethink your code to cover cases like ours. WORKAROUND We created a file (vue-jest.js) that replicates the function from "vue-jest/lib/process" with the following content:
Then in the jest configuration, we just refer to this file:
Now it works like a charm! I hope it helps someone. |
I have the same issue with aliast in src of the template in vue-jest 3.0.6 (and I believe 4.x will have the same problem) In index.vue I have: <template src="@components/template.html" /> package.json: {
"scripts": {
"start": "webpack-dev-server",
"test": "jest",
"tdd": "jest --watch"
},
"repository": "GadQ/vue-jest-template-alias",
"dependencies": {
"vue": "^2.6.10"
},
"devDependencies": {
"babel-core": "7.0.0-bridge.0",
"jest": "^26.4.1",
"vue-jest": "^3.0.6",
"vue-loader": "^15.7.0",
"vue-template-compiler": "^2.6.10",
"webpack": "^4.30.0",
"webpack-cli": "^3.3.1",
"webpack-dev-server": "^3.3.1"
}
} jest.config.js: module.exports = {
moduleFileExtensions: [ 'js', 'vue' ],
transform: {
'^.+\\.vue$': 'vue-jest'
},
moduleNameMapper: {
'^vue$': 'vue/dist/vue.js',
'^@components/(.*)$': '<RootDir>/components',
},
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.{js,vue}'
]
} When I run the test I get: Alias isn't resolved, but added as relative to tested index.vue directory path. When i use relative path test works i.e. <template src="./components/template.html" /> Besides that webpack/vue-loader doesn't have any problem with path with alias and build project correctly. Reproduction repository: https://github.com/GadQ/vue-jest-template-alias. |
I used external template like :
Success when building production file using
[email protected]
.But unit test failed to run using
[email protected]
Here some snippet of my Jest configuration :
Error that I got is :
if I look into error message, it because pointing to my project root folder instead of
node_modules
folder.Is there any missing from my side ?
Thanks for all response 👍
The text was updated successfully, but these errors were encountered: