我遇到了這個測試問題,我不知道如何測試組件settimeout。任何人都有關於如何測試以下組件的建議:settimeout?非常感謝反應如何用setTimeout測試出反應組分
import React, { PropTypes, Component } from 'react';
import styles from '../../../css/notification.css';
export default class Notification extends Component {
static propTypes = {
tagMetaUpdate: PropTypes.shape({
submitUpdatedTagDataSuccessful: PropTypes.bool
}),
actions: PropTypes.shape({
resetUpdatedTagDataSuccessfulFlag: PropTypes.func
})
};
constructor(props) {
super(props);
this.state = {
showMessage: true
};
}
hideMessage(actions) {
this.timer = setTimeout(() => {
this.state.showMessage = false;
actions.resetUpdatedTagDataSuccessfulFlag();
this.forceUpdate();
}, 3000);
}
render() {
const { tagMetaUpdate, actions } = this.props;
const output = (tagMetaUpdate.submitUpdatedTagDataSuccessful && this.state.showMessage) ?
<div className={styles.notification}>Tag meta data successfully edited.</div> : null;
if (this.props.tagMetaUpdate.submitUpdatedTagDataSuccessful) {
this.hideMessage(actions); // HERE IS THE BIT BLOCKING ME
}else {
this.state.showMessage = true;
}
return <div>{output}</div>;
}
}