3

I'm trying to test my components with jest, react, redux but I keep getting the following error:

 ● Test suite failed to run
        stream-react-redux/src/containers/App/App.css:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){.app {

    SyntaxError: Unexpected token .

I have followed the instructions on how to add the identity-obj-proxy and configuring my .jestrc file, but I keep getting the same error. The problem came when I started using css-modules and importing them in my components

Here is my .jestrc:

{
  "moduleFileExtensions": [ "js", "jsx"],
  "moduleNameMapper": {
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
    "^.+\\.(css)$": "identity-obj-proxy"
  },
  "transform": {
    "^.+\\.(js|jsx)$": "babel-jest"
  },
  "verbose": true
}

I have also added the ["es2015", { "modules": false } ] inside my .babelrc file.

2 Answers 2

5

So after trying everything, I was still getting the same error.

What I just noticed is that when I specify my config inside a .jestrc file my tests brake because of the .css, but when I do it from the package.json everything works.

EDIT

#package.json


  "jest": {
    "moduleNameMapper": {
      "\\.css$": "identity-obj-proxy"
    }, 
    "transform": {
      "\\.js$": "babel-jest"
    }
Sign up to request clarification or add additional context in comments.

2 Comments

Rename .jestrc to jest.config.js and restart jest)
Adding these jest settings to package.json worked for me.
2

I took a look at the Jest docs and, just to be clear, did you install identity-obj-proxy?

npm install --save-dev identity-obj-proxy

Also, I see that the recommended file regex in the Jest docs is

"\\.(css|less)$": "identity-obj-proxy"

may try switching yours to match.

Finally, you could try a jest plugin like jest-css-modules

https://github.com/justinsisley/Jest-CSS-Modules

1 Comment

I have actually tried everything, but still getting the same error What I just noticed is that when I specify my config inside a .jestrc file my tests brake because of the .css , but when I do it from the package.json everything works. I added an edit to my question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.