gatsby-plugin-react-svg icon indicating copy to clipboard operation
gatsby-plugin-react-svg copied to clipboard

Mocking Component in Jest

Open TannerJuby1 opened this issue 3 years ago • 1 comments

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?

TannerJuby1 avatar Feb 24 '22 22:02 TannerJuby1

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

jacobmischka avatar Feb 24 '22 23:02 jacobmischka