I'm trying to test some React components with Jest.
I can successfully test a) plain JS files and b) React components written in CJSX (Coffeescript and JSX). There was some configuration required using a preprocessor for Jest to process the CJSX files into JS - but that seems to work. At least I can test simple React components written in CJSX. I don't think this problem is specific to compiling CJSX files.
However: when I bring in react-bootstrap there are problems. This is necessary because all of the components I want to test use react-bootstrap.
This occurs equally when I am unmocking react-bootstrap and when I am leaving Jest to automatically mock it. Either way it has to parse the files in its test runner - and this is when the problem occurs.
This is the specific error message:
SyntaxError: path/components/scripts.cjsx: /node_modules/react-bootstrap/lib/index.js: /node_modules/react-bootstrap/lib/utils/bootstrapUtils.js: /node_modules/react-tools/src/vendor/core/warning.js: Unexpected token ...
scripts.cjsx is the file which contains the component I am trying to test - and the file in which I do require 'react-bootstrap'
And the full stacktrace is:
at Object.exports.runInContext (vm.js:43:16)
at JSDOMEnvironment.runSourceText (node_modules/jest-cli/src/environments/JSDOMEnvironment.js:40:10)
at Object.runContentWithLocalBindings (node_modules/jest-cli/src/lib/utils.js:378:17)
at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:234:11)
at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:845:14)
at Loader.requireModuleOrMock (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:875:19)
at Object.<anonymous> (node_modules/react-bootstrap/lib/utils/bootstrapUtils.js:19:16)
at Object.runContentWithLocalBindings (node_modules/jest-cli/src/lib/utils.js:397:17)
at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:234:11)
at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:845:14)