Jest:模拟组件子功能

时间:2018-03-20 15:29:42

标签: reactjs jestjs

我有这样的组件:

class Columns extends React.Component {
  fetchCSVData = async () => {            <-- this function
    const { ownerId } = this.props;
    const CSVTrackResponse = await getCSVClientReport({ ownerId });
    fileDownload(CSVTrackResponse, 'lifetimeTracks.csv');
  };

  render() {
    const children = React.Children.map(this.props.children, child => {
      return React.cloneElement(child, {
        onDownload: () => this.fetchCSVData()
      });
    });
    return <ColumnsContainer>{children}</ColumnsContainer>;
  }
}


const Reports = ({ ownerId }) => (
  <Container>
    <Header>Reports</Header>
    <Columns ownerId={ownerId}>    <-- this component has a inner function
      <Cell title="LIFETIME TRACKS" />
    </Columns>
  </Container>
);

我想拍摄Reports组件的快照。我应该如何使用Columns模拟jest的内部函数,Reports是{{1}}组件中的子组件?

任何提示都很棒

0 个答案:

没有答案