繁体   English   中英

如何测试提供给子组件的 function?

[英]how to test a function which is provided to children component?

我正在对 jest 进行测试,它说某些代码行没有被覆盖。 在我的情况下,它是定义 Resizable 组件的行。 这个组件来自 npm package 称为“re-resizable”

class SomeComponent extends Component {
    constructor(props) {
        super(props)
        this.state({
            height: 0
        })
    }
    render() {
        return (
            <div>
               <Resizable
                  onResizeStop={(e, direction, ref, d) => {
                      this.setState({
                          height: this.state.height + d.height
                      })
                  )}
               />
            </div>
        )
    }
}

所以似乎我必须测试为 Resizable 组件提供 function 的 onResizeStop 道具。 如何触发 onResizeStop 事件并断言高度 state 已更改? 我正在使用酶版本 3.10.0 和开玩笑版本 26.5.3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM