【发布时间】:2020-06-05 07:35:53
【问题描述】:
我正在使用 React、Enzyme 和 Jest。这是我的连接组件,它只呈现一个按钮
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';
我错过了什么?我为也导入模块的其他组件制作了成功的测试套件。但是这个特别给我带来了问题。
【问题讨论】:
-
为什么需要将 PlaidLinkButton 导入到测试中?你不只是浅渲染ConnectStep吗?我也想看看整个测试文件
-
我不需要这是我试图避免的。我确实是浅渲染。这就是我无法弄清楚这个错误的原因。
标签: javascript reactjs jestjs jsx enzyme