【发布时间】:2019-01-27 01:30:19
【问题描述】:
我有一个 HOC 组件。
const SectionComponent = (ComponentToWrap) => {
return function ComponentToWrapWithLoading({...props}) {
const { isLoading, isLoaded, icon, title } = props;
if (!isLoading && isLoaded )
return (
<div>
<SectionHeading icon={icon} title={title} />
<ComponentToWrap {...props} />
</div>
);
if (isLoading)
return (<Loader />);
return null;
};
};
export default SectionComponent;
我在反应组件中使用的:
import React, {Component} from 'react';
import SectionComponent from '../../UI/section/Section'
import { faDumbbell} from '@fortawesome/free-solid-svg-icons';
import TableWrapper from '../../UI/table/Table-wrapper';
const SectionLoadingComponent = SectionComponent(TableWrapper);
export class TrainingsList extends Component {
componentDidMount() {
const {fetchTrainings} = this.props;
fetchTrainings();
}
getTableColumns() {
...
}
render() {
const { isLoading, isLoaded, data } = this.props.trainings;
const columns = this.getTableColumns();
return(
<div>
<SectionLoadingComponent
isLoading={isLoading}
isLoaded={isLoaded}
title='Lista ćwiczeń'
icon={faDumbbell}
data={data}
columns={columns}
/>
</div>
);
}
}
我的问题是我不知道如何在单元测试中模拟 SectionLoadingComponent 我尝试使用 react test-renderer,但组件未渲染。 我将非常感谢一些提示和技巧。
【问题讨论】:
标签: reactjs unit-testing mocking jestjs higher-order-components