我有这样的组件:
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}}组件中的子组件?
任何提示都很棒