Reactjs 为什么不输入componentDidUpdate()?

Reactjs 为什么不输入componentDidUpdate()?,reactjs,jestjs,enzyme,Reactjs,Jestjs,Enzyme,您好,我正在尝试测试一个状态,该状态在组件diddupdate中发生了更改,但不是eNet 代码 测试呢 it('should set nextButtonDisabled to false when gets new props.datasource if datasource length <= 20', () => { const component = shallow(<VehicleHistoryTable {...makeProps()} />)

您好,我正在尝试测试一个状态,该状态在
组件diddupdate
中发生了更改,但不是eNet

代码

测试呢

it('should set nextButtonDisabled to false when gets new props.datasource if datasource length <= 20', () => {
    const component = shallow(<VehicleHistoryTable {...makeProps()} />)
    component.setProps({ dataSource: createDataSourceMock(3) })
    expect(component.instance().state.paginationInfo.nextButtonDisabled).toEqual(true)
})

it('gets new props.datasource时应将nextButtonDisabled设置为false如果datasource length不确定您使用的参数是否正确,这就是方法签名
componentDidUpdate(prevProps、prevState、snapshot)
from。因此,您可以将以前的道具和状态与当前道具和状态进行比较。这不是一个无限循环吗?您在
componentdiddupdate
中设置状态,触发重新渲染,再次调用
componentdiddupdate
,否?是否存在生命周期方法?可能这会阻止更新?还请确保使用enzyme version>=3,因为以前的版本没有在浅层渲染上触发
componentDidUpdate
方法。
this.state = {
    paginationInfo: {
        currentPage: 0,
        nextButtonDisabled: true
    }
}
it('should set nextButtonDisabled to false when gets new props.datasource if datasource length <= 20', () => {
    const component = shallow(<VehicleHistoryTable {...makeProps()} />)
    component.setProps({ dataSource: createDataSourceMock(3) })
    expect(component.instance().state.paginationInfo.nextButtonDisabled).toEqual(true)
})