如何在测试期间使用Jest导入模块?

时间:2020-02-20 21:50:25

标签: javascript reactjs jestjs jsx enzyme

我正在使用React,Enzyme和Jest。这是我的connect组件,仅呈现一个按钮

       services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
            .AddAzureAD(options => Configuration.Bind("AzureAd", options));

如您所见,我正在导入PlaidLinkBut​​ton,但开玩笑会抛出此错误:

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>
    );
  }
}

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

1 个答案:

答案 0 :(得分:0)

    import PropTypes from 'prop-types';
           ^^^^^^^^^

    SyntaxError: Unexpected identifier

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

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