我有这个组件,可以加载图像,然后仅在图像加载后显示内容(检查图像加载状态)。如何编写笑话测试以测试它是否正常工作,并且仅在加载图像后才显示内容,而不显示内容?
import HeaderImage from '../images/headerimage.svg';
const ImageStyled = styled.img`
margin-left: -0.1rem;
`;
export default class ImageDisplay extends Component {
constructor(props) {
super(props);
this.state = { imageStatus: 'loading' };
}
handleImageLoaded() {
this.setState({ imageStatus: 'loaded' });
}
renderContent = () => (
if (this.state.imageStatus === 'loading') {
return null;
}
else {
<div>
Some Sample Content
</div>
}
render() {
return (
<div>
<ImageStyled
src={HeaderImage}
onLoad={() => {
this.handleImageLoaded();
}}
/>
{this.renderContent()}
</div>
);
}
}
`