jacobmischka / gatsby-plugin-react-svg

Adds svg-react-loader to gatsby webpack config
https://www.npmjs.com/package/gatsby-plugin-react-svg
MIT License
70 stars 21 forks source link

Mocking Component in Jest #51

Open TannerJuby1 opened 2 years ago

TannerJuby1 commented 2 years ago

How do you mock these SVG components in Jest?

I import it in my files like suggested, but when it tries to retrieve it I get an error that the Module could not be found.

If I try the suggested Code Transform method from Jest allows the tests to pass, but I get an error because the import ends up being <MyIcon.svg /> which is invalid syntax.

Can we get some documentation on how to test components that use this plugin?

jacobmischka commented 2 years ago

No idea, you'll want to look for solutions for doing the same with the underlying library. This may help: https://stackoverflow.com/questions/46583986/how-can-i-ignore-svg-react-loader-path-to-my-svg-when-testing-with-jest-wi