如何在使用笑话的测试过程中导入模块?

问题描述 投票:0回答:1

我正在使用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>
    );
  }
}

您可以看到我正在导入PlaidLinkBut​​ton,但开玩笑会抛出此错误:


    ###/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';

我想念的是什么?我为其他也导入模块的组件制作了成功的测试套件。但这尤其给我带来了问题。

javascript reactjs jestjs jsx enzyme
1个回答
0
投票
    import PropTypes from 'prop-types';
           ^^^^^^^^^

    SyntaxError: Unexpected identifier

这可能与您的Jest / Babel配置有关,因为模块未正确编译。您需要删除将Babel选项modules设置为false的任何位置。

相关:https://github.com/facebook/react/issues/14399

© www.soinside.com 2019 - 2024. All rights reserved.