如何使用开玩笑/酶测试resizeObserver回调函数
我有一个使用resizeObserver
显示/隐藏某些样式的组件。
样式的切换正在函数中发生,将由resizeObserver
回调触发。
component.tsx
private toggleStyles() {
const applyStyles = some condition here...
this.setState({ applyStyles });
}
private observeResize = () => {
this.resizeObserver = new ResizeObserver(() => this.toggleStyles());
this.resizeObserver.observe(element to observe here..);
}
componentDidMount() {
this.observeResize();
}
componentWillUnmount() {
if (this.resizeObserver) {
this.resizeObserver.disconnect();
}
}
我想测试resizeObserver
回调,该回调会触发togglestyles
函数,但是我不确定如何在元素本身上触发调整大小。
I have a component that uses the ResizeObserver
to show/hide some styles.
the toggling of the styles is happening in a function the will be triggered by the ResizeObserver
callback.
component.tsx
private toggleStyles() {
const applyStyles = some condition here...
this.setState({ applyStyles });
}
private observeResize = () => {
this.resizeObserver = new ResizeObserver(() => this.toggleStyles());
this.resizeObserver.observe(element to observe here..);
}
componentDidMount() {
this.observeResize();
}
componentWillUnmount() {
if (this.resizeObserver) {
this.resizeObserver.disconnect();
}
}
I want to test the ResizeObserver
callback that will trigger the toggleStyles
function, but I'm not sure how can I trigger the resize on the element itself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论