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

Unable to get query params to work with Jest #57

Closed
joebanks10 opened this issue Jan 9, 2019 · 4 comments
Closed

Unable to get query params to work with Jest #57

joebanks10 opened this issue Jan 9, 2019 · 4 comments

Comments

@joebanks10
Copy link

Hello, I'm having trouble getting imports w/ query params to work in a Jest environment. I set up an example project here:

https://github.com/joebanks10/jest-next-optimized-images

Is there something I need to add to get it to work?

@joebanks10
Copy link
Author

I was able to get images to work by mocking them in the tests. In jest.config.js:

module.exports = {
  testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
  moduleNameMapper: {
    '^.+\\.(gif|png|jpg|ttf|eot)\\?(resize|sizes)(.+)?$':
      '<rootDir>/__mocks__/fileResizeMock.js',
    '^.+\\.(gif|png|jpg|ttf|eot)(\\?.+)?$': '<rootDir>/__mocks__/fileMock.js',
    '^.+\\.svg\\?(sprite|include)(.+)?$': '<rootDir>/__mocks__/svgMock.js',
  },
}

Full example can be found in the repo: https://github.com/joebanks10/jest-next-optimized-images

@cyrilwanner
Copy link
Owner

Hi @joebanks10
Thanks a lot for the example repository! The way you did it is probably the easiest one, I'll try to include the mocks you provided directly in the package so they are always up-to-date and it is a bit easier to set up.

@makarov-foot
Copy link

makarov-foot commented Mar 18, 2019

@joebanks10 's repo now throws

Cannot find module '../static/cart.svg?sprite' from 'index.js'

it can't resolve name because of query prefix.

Does somebody know how to fix this?

@cyrilwanner
Copy link
Owner

Hi @makarov-foot
I just checked out his repository and it is working for me without any error. I only run npm install and npm test and all tests are passing.

Are you sure that you didn't modify his jest.config.js file? Or did you configure jest in a special way or did any other modification to his project?

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

3 participants