Skip to content
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

SVG imports not working with yarn rw test #391

Closed
RobertBroersma opened this issue Apr 6, 2020 · 3 comments
Closed

SVG imports not working with yarn rw test #391

RobertBroersma opened this issue Apr 6, 2020 · 3 comments

Comments

@RobertBroersma
Copy link
Contributor

Jest doesn't know how to handle .svg imports.

A mock transformer should be implemented.

What I usually do is just transform the SVG into an empty module (in this case it needs to be something react-y I assume since svg-react-loader transforms SVG's into Components.

What is a good generic way to transform SVG's like that? Is stubbing them out to be nothing too limiting for some people who want to assert on the SVG?

Happy to create a PR if we can clear this up!

@thedavidprice
Copy link
Contributor

Curious if you're implementing Jest tests currently or simply thinking ahead? Asking because we've yet to finish implementing built-in Jest support -- yes, you can run yarn rw test but as soon as you start importing it's failing all over the place. So if you're already up and running on your own, let's talk! 😀

Back to your question, yes, I think the way forward here will be jest.mock(). I'll fully defer to @peterp however.

Update on CRA Jest support:
Peter and Rob are just about done with test implementation for our CLI package. We'll use the fixtures pattern for CRA implementation as a helper/utility. For examples see here and here. Mentioning this in the case it seems we should sync this request with next steps on CRA Jest support.

@RobertBroersma
Copy link
Contributor Author

Ah, great!

I didn't realize it's not done yet. I figured I can run it = I'm supposed to be able to run it.

I tried running yarn rw test in my web package and this was the first issue that came up, but I'll certainly wait for the PR you linked to be merged!

PS. I think using the moduleNameMapper or maybe transformer option in Jest Config would be simpler than using jest.mock()

@RobertBroersma
Copy link
Contributor Author

Fixed by #521

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants