Testing react-redux
Hi! I am using react-redux in one of my npm packages (the package is using react-redux). How would I go about testing my app?
Below is a reference to the same problem:
I have the same issue with "react-redux".
• Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
[...]
Details:
***\node_modules\react-redux\es\connect\connect.js:5
import connectAdvanced from '../components/connectAdvanced';
^^^^^^
SyntaxError: Unexpected token import
4 | import LoginMethodComponent from './LoginMethodComponent';
5 | import { startPollUpdateBankIDStatus } from '../../../redux/modules/bankID/userBankIDReducer';
> 6 | import connect from 'react-redux/es/connect/connect';
| ^
7 | import { bindActionCreators } from 'redux';
8 |
9 | export class LoginMethodContainer extends React.Component {
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
at Object.<anonymous> (src/components/user/login/LoginMethodContainer.js:6:1)
at Object.<anonymous> (src/components/user/login/__tests__/LoginMethodContainer.test.js:3:1)
The temporary fix for now seems to be to specify "transformIgnorePatterns" as mentioned above:
"scripts": {
...
"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!(react-redux))/\"",
...
},
Originally posted by @jangerhard in https://github.com/facebook/create-react-app/issues/5241#issuecomment-426986623