SyntaxError with Jest and React and importing CSS files

后端 未结 7 1133
-上瘾入骨i
-上瘾入骨i 2020-12-02 17:01

I am trying to get my first Jest Test to pass with React and Babel.

I am getting the following error:

SyntaxError: /Users/manueldupont/test/av

7条回答
  •  时光取名叫无心
    2020-12-02 17:21

    UPDATE who use create-react-app from feb 2018. You cannot override the moduleNameMapper in package.json but in jest.config.js it works, unfortunately i havent found any docs about this why it does. So my jest.config.js look like this:

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

    and it skips scss files and @import quite well.

    Backing my answer i followed jest webpack

提交回复
热议问题