Andreea
Andreea

Reputation: 521

How I can unit test componentWillReceiveProps(nextProps) with jest?

How cand I unit test componentWillReceiveProps(nextProps) with jest?

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
        });
    }  
}

Upvotes: 0

Views: 1209

Answers (1)

Adrian Warkocz
Adrian Warkocz

Reputation: 657

I think here is the answer for you question https://medium.com/@pchomphoosang/react-js-how-to-do-unit-testing-on-componentdidmount-componentwillreceiveprops-866385c3e5dc

But I would recommend moving your code from componentWillReceiveProps to shouldComponentUpdate since CWRP is deprecated.

Upvotes: 1

Related Questions