我正在使用React,Enzyme和Jest。这是我的connect组件,仅显示一个按钮
import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core/styles';
import PlaidLinkButton from 'react-plaid-link-button';
const plaidEnv = process.env.REACT_APP_PLAID_ENV
export class ConnectStep extends Component {
handleOnSuccessBroker = async (token, metadata) => {
//unimportant
};
render() {
const { classes } = this.props;
return (
<PlaidLinkButton
buttonProps={{
className: classes.connectButton,
id: 'button',
}}
plaidLinkProps={{
clientName: '###',
key: '###',
env: plaidEnv,
product: ['transactions'],
onSuccess: this.handleOnSuccessBroker,
token: ''
}}
>
{this.props.plaid.accounts.length > 0 ? 'CONNECTED' : 'Start'}
</PlaidLinkButton>
);
}
}
您可以看到我正在导入PlaidLinkButton,但开玩笑会抛出此错误:
###/node_modules/react-plaid-link-button/dist/react-plaid-link-button/react-plaid-link-button.js:19
import PropTypes from 'prop-types';
^^^^^^^^^
SyntaxError: Unexpected identifier
4 |
5 | import { setPlaid } from '../../../actions/actions';
> 6 | import PlaidLinkButton from 'react-plaid-link-button';
我想念的是什么?我为其他也导入模块的组件制作了成功的测试套件。但这尤其给我带来了问题。
import PropTypes from 'prop-types';
^^^^^^^^^
SyntaxError: Unexpected identifier
这可能与您的Jest / Babel配置有关,因为模块未正确编译。您需要删除将Babel选项modules设置为false
的任何位置。