Accepted answer

Mocha probably can't read your TestComponent because it contains syntax unfamiliar to it (the JSX). You'll need to specify a compiler for mocha as well as babel presets (assuming you're using Babel).

Assuming you already have babel-core and babel-preset-react installed for your project, make these changes in your package.json:

"scripts": {
  "test": "mocha --compilers js:babel-register \"./src/**/*.spec.js\""
"babel": {
  "presets": ["react"]


You should add the .jsx extension to your require call, as by default it won't recognize .jsx files as modules.

Rick is also right about the compiler but in this case the error is due to the synthax of require. Then if you fix the require you will see an error of unexpected token, which is the lack of compiler.

You should therefore correct both points.

Related Query

More Query from same tag