react-relative-portal是一个包,用于在组件外部创建html,以便忽略溢出属性 . 问题在于,当我测试反应组件和我想要测试的部件超出了安装组件的范围时 . 我不知道如何继续测试它 .

class MyComponent extends Component{
    constructor(){
        this.state={
        showPotal: false
        }
    }
    handleClick = () => {
        this.setState((prevState) =>{
        showPortal: !prevState.showPortal
        })
    }
    render(){
        <button onClick={this._handleClick}>show portal</button>
            {this.state.showPortal && (
                <RelativePortal component="div">
                        <Portal />
                </RelativePortal>
            )}
    }
}

正如您所看到的那样,因为 <Portal /> 位于 <RelativePortal /> 内部,因此会在组件外部呈现 . 我不知道如何在 <MyComponent /> 的上下文中找到 <Portal />