How to test a prop update on React component

前端 未结 8 581
鱼传尺愫
鱼传尺愫 2020-12-14 05:36

What is the correct way of unit testing a React component prop update.

Here is my test fixture;

describe(\'updating the value\', function(){
                 


        
8条回答
  •  没有蜡笔的小新
    2020-12-14 06:38

    Quick addition, as I was looking for an answer for testing-library, and didn't find it here: there's an example in this issue, and it looks like this:

    const {container} = render()
    
    // update the props, re-render to the same container
    render(, {container})
    

    Alternatively, testing-library now offers a "rerender" method that accomplishes the same thing.

提交回复
热议问题