0

I wrote a React application and used jest to write unit tests.

when I run it by "jest --config=jest.config.json --watch" I get the following error:

Test suite failed to run

/home/user/Projects/react-game/src/Square.css:1
({"Object.>

":function(module,exports,require,__dirname,__filename,global,jest){.bluePawn, .blueMasterPawn, .redPawn, .redMasterPawn { ^ SyntaxError: Unexpected token .

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
  at Object.<anonymous> (src/MasterPawn.js:3:1)
  at Object.<anonymous> (src/Utils.js:3:19)

I just want to note that compiler marks ".bluePawn" which is a class name. Therefore, I understand that it cannot read class name.

It looks like something that has to do with configurations. I was searching on the web, and didn't find any solution that could help me.

2
  • Are you importing any css files inside your components? Commented May 2, 2018 at 21:59
  • yes. css files are imported to my components Commented May 2, 2018 at 22:00

1 Answer 1

1

Create an empty css file named stub.css inside src.

Then add this to your package.json :

"jest": {
    "moduleNameMapper": {
      ".*css$": "<rootDir>/src/stub.css",
    },
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, but now I see that the error has changed: stackoverflow.com/questions/50144229/…
It looks like an error related to the tests themselves, and not the config of jest

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.