I am new in Unit Testing for React. I have a question regarding the if statement. I need test the function of componentwillreceiveprops, I know I can use spy = sinon.stub(component.props,"componentwillreceiveprops") method to let spy be called.
But in my component, there is an if statement, such as
componentwillreceiveprops(nextProps){
if(this.props.name!==nextProps.name) {
this.setState({
oldstate: newstate
})
}
}
I can make the componentWillReceiveProps
function called. If I remove the if statement, the setState function can be called either. But what I have in my component contains a if statement, it is not called when I run the unit testing. Is there any way to make this if statement called? Thank you in advance.