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
Setup Jest when Internal and External SVGs are configured #73
Comments
Have you tried reversing the rule definition in the inline / external example webpack config? `chainWebpack: config => {
}` Doing this will allow you to safely import svg's for inline usage within your script tags, without the tests crashing. The caveat is that whenever you will need to import the svg's into the scrip tag without the external resourceQuery, using the file-loader, the tests will crash. Until recently, this wasn't much of a problem for me, as I only loaded svgs via the file-loader (with the external resource query) in css files, which jest does not pick up. |
@jpetko Here's a better solution that seems to work without the above stated caveat. You update your vue.config.js file as recommended by the vue-svg-loader docs to support both inline and external uses of svg files. It should look something like this:
To fix the crashing jest unit tests, you need to properly resolve the modules imported with resourceQuery strings. To do this, you use a moduleNameMapper, your jest.config.js file should look something like this:
The line that interests you is this one, Doing this, you should be able to safely use inline svgs by importing them with the following syntax:
Your jest suits should work fine now. If this is an acceptable solution, it would be useful to have this in the project docs. |
I think it is worth putting this into the FAQ section :) |
does the regex for the mapper target relative imports? and if not how would that look like? |
@acazacu Thank you so very very much! I was going insane with this, had your same exact configuration except the order in the mapper. That was it!!! |
Hi, I was curious as how to configure the Jest transform when inline and external svgs are in use with the '?inline' method shown in the FAQ?
I get a 'Could not locate module' error when the unit test hits the import statement now.
The text was updated successfully, but these errors were encountered: