-
Notifications
You must be signed in to change notification settings - Fork 84
How to add it to Jest configuration? #38
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
There is one major issue when it comes to integrating
If your SVGs are prepared, create a transform file named for example const vueJest = require('vue-jest/lib/template-compiler');
module.exports = {
process(content) {
const { render } = vueJest({
content,
attrs: {
functional: false,
},
});
return `module.exports = { render: ${render} }`;
},
}; And then modify your module.exports = {
transform: {
'^.+\\.svg$': '<rootDir>/path/to/svgTransform.js',
},
}; To test if everything works you need to start the tests with the |
@koresar have you had a chance to test the solution above? |
Hello.
Sorry mate. I had no chance.
We've decided to just rename the file extension from .svg to .vue and wrap
it in the <template> tag. As the result no additional configuration needed
anywhere.
Cheers
…On Wed., 25 Jul. 2018, 20:50 Damian Stasik, ***@***.***> wrote:
@koresar <https://github.com/koresar> have you had a chance to test the
solution above?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#38 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABjCL1pdCsnd8I9q5aMSLeYmWxK9iWNdks5uKE2LgaJpZM4VfZIZ>
.
|
No problem at all 👍 |
Just wanted to say that I also had this error, and your solution works like a charm with no modification 👍 Thanks! |
@koresar If that didn't work for you, check whether If you're using Vue CLI, it probably generated a line for all assets (including SVGs) that gets transformed with module.exports = {
// ...
transform: {
// ...
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.svg$': '<rootDir>/svgTransform.js'
}
} |
I follow the instruction of adding loader to jest but this error appears |
any update on this? Im running into the exact same error. |
if your svg files have ?xml ? you'll get the error. So need just remove it: const vueJest = require('vue-jest/lib/template-compiler'); module.exports = {
} |
i removed my ?xml and still am encountering the above issue
|
Solution from @visualfanatic worked! However as I was using a later version of babel, I had to install babel bridge to make vue-jest compile properly. npm i -D babel-core@^7.0.0-bridge.0 |
Hi folks, This solution is not working anymore after updating to Does anyone figured out another workaround? Thanks! |
@joaopslins It took a bit of digging, but here's how I got this working for Update
jest.config.js stays the same:
And as @visualfanatic pointed out, make sure you run jest with the
Otherwise you may not see any impact after updating For reference: |
As a sidenode, make sure to run --clearCache after you make this change... Since |
@anthonylebrun Thank you! This worked well! I appreciate the help 🙇 |
Uh oh!
There was an error while loading. Please reload this page.
The
MyComponent
is importing an SVG file, and then using it in the code. I cannot unit test such component because vue-svg-loader is not configured in my Jest.The unit test throws... Cannot render the SVG.
How to add
vue-svg-loader
to the Jest configuration?The text was updated successfully, but these errors were encountered: