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

Webpack require() assets #41

Closed
cgatian opened this issue Jun 2, 2017 · 3 comments
Closed

Webpack require() assets #41

cgatian opened this issue Jun 2, 2017 · 3 comments

Comments

@cgatian
Copy link

cgatian commented Jun 2, 2017

Looks like this issue has been answered several times on the internet but nothing seems to work for me.

The approach I tried was to redirect the require to a mock, as suggested by the Jest Webpack documentation

"moduleNameMapper": {
      "\\.(jpg|jpeg|png)$": "<rootDir>/__mocks__/fileMock.js"
    },

This approach seems to work for the majority of users, but for some reason isn't for me. I understand all setups are a little different, but I'm wondering if anyone has ran into this issue while running the preset, and how they solved it.

@thymikee
Copy link
Owner

thymikee commented Jun 7, 2017

Hard to tell without a repo where the problem happens. Are you able to provide such? Otherwise there's little I can do

@cgatian
Copy link
Author

cgatian commented Jun 8, 2017

In your Angular CLI project example if you attempt to require a png file within a component that's under test, you should see the issue.

I will attempt to fork your repo to show later tonight.

@thymikee
Copy link
Owner

thymikee commented Jun 8, 2017

Can you send a PR with failing test which we can fix later?

@cgatian cgatian mentioned this issue Jun 9, 2017
thymikee added a commit that referenced this issue Sep 6, 2017
In #6 we introduced very loose moduleNameMapper which resulted in couple of weird bugs and until next Jest release it's impossible to override it.

This PR reverts it and adds some reasonable defaults.

Also, because of this "(.*)"mapping, while debugging #41 on master version of Jest, I encountered an issue where one of the internal Jest modules was calling path matching the regexp, but couldn't find it under src dir. This surfaced only because Jest version on master supports checking if modules in moduleNameMapper exist and throws otherwise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants