score:1

Accepted answer

There is a small mistake: moduleNameMapper: {moduleNameMapper{}} should just be moduleNameMapper:{}

"moduleNameMapper": {
  "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
  "\\.(css|less)$": "identity-obj-proxy"
}

score:1

It may work who use create-react-app from feb 2018. I partially followed the docs jest webpack to make it work.

Also found out the moduleNameMapper cannot be overriden in package.json but in jest.config.js it does the trick. Unfortunately i havent found any docs about why it does but here is my answer. Here is my jest.config.js:

module.exports = {
...,
  "moduleNameMapper": {
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
    "\\.(scss|sass|css)$": "identity-obj-proxy"
  }
}

and it skips scss files and @import quite well.

I added to devDependencies identity-obj-proxy


Related Query

More Query from same tag