我怎样才能用笑话对componentWillReceiveProps(nextProps)进行单元测试?

时间:2019-07-16 08:49:09

标签: react-native testing jestjs

我如何才能用笑话来对componentWillReceiveProps(nextProps)进行单元测试?

componentWillReceiveProps(nextProps) {
    if (nextProps.data === undefined || 
        nextProps.data.hasOwnProperty('error') || 
        nextProps.err !== undefined) {
        this.setState({
        messageError: "Something went wrong!"
        });
    }  else if ((nextProps.data).length) {
        this.setState({
            dataArray: nextProps.data
        });
    }  
}

1 个答案:

答案 0 :(得分:1)

我认为这是您的问题https://medium.com/@pchomphoosang/react-js-how-to-do-unit-testing-on-componentdidmount-componentwillreceiveprops-866385c3e5dc

的答案

但是我建议您将代码从componentWillReceiveProps移至shouldComponentUpdate,因为CWRP已弃用。