How to handle `responsive-loader` with jest/CRA?
See original GitHub issueI am using CRA with responsive-loader, and I am getting the following errors:
FAIL src/pages/User/test.tsx
● Test suite failed to run
Cannot find module './assets/user_background.jpg?min=320&max=800&steps=3' from 'index.tsx'
However, Jest was able to find:
'./index.tsx'
You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].
See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string
20 |
> 21 | const userBackground = require('./assets/user_background.jpg?min=320&max=800&steps=3')
| ^
22 |
Are there any solutions to fix the test?
The only way around it I can find it edit my import into const userBackground = require('./assets/user_background.jpg')
and so not having any benefits of the loader.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to handle responsive-loader with jest/CRA? #86 - GitHub
I am using CRA with responsive-loader, and I am getting the following errors: FAIL src/pages/User/test.tsx ○ Test suite failed to run ...
Read more >responsive-loader - npm
A webpack loader for responsive images. Latest version: 3.1.2, last published: a month ago. Start using responsive-loader in your project by ...
Read more >Create a responsive loader content - Stack Overflow
This gives you less control over the SVG via CSS but is supported by more browsers than the first method. Try expanding the...
Read more >testing support for the experimental syntax 'jsx' isn't currently ...
Answers related to “testing support for the experimental syntax 'jsx' isn't currently enabled” ; 'React' must be in scope when using JSX react/react-in-jsx-scope ......
Read more >Fallback Loader - sage - Roots Discourse
For anyone using background images in their css and having issues with file sizes, I added url-loader and responsive loader as my fallback...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I did overcome the same issue by adding in my jest configuration:
and within
__mocks__/jpgPngMock.js
:I ended up applying the
babel-plugin-import-remove-resource-query
plugin to jest, and then mocked the file inside the test: