【发布时间】:2019-03-01 09:07:51
【问题描述】:
我一直在尝试在我的 react 项目中测试 Callout 组件。
为简单起见,以下是 React 渲染组件:
<div className="UserInfoDiv">
<div ref={this.menuButtonElement}>
<ActionButton id="toggleCallout"
onClick={changeIsCallOutVisibleProptoTrue}
text="Show Callout" />
</div>
<Callout
className="calloutClass1"
target={this.menuButtonElement.current}
hidden={!this.props.isCalloutVisible}>
<div id="callOutContainer">
<span>Need to test items here.<span>
<button className="clickForSomeAction">Simulate Click on this</button>
</div>
</Callout>
</div>
这在 UI 中工作得非常好。为了开玩笑地进行测试,我尝试了以下操作:
userMenu = mount(<UserInfoDivComponent {...props} />);
UserInfoDiv.find("button#toggleCallout").simulate('click');
expect(changeIsCallOutVisibleProptoTrue.mock.calls.length).toBe(1);
userMenu.setProps({isCalloutVisible: true });
// Following only gives html(included UserInfoDiv,toggleCallout) `without html from callout`:
console.log(userMenu.html());
我需要帮助,如何测试以下场景?
- 标注可见?
- 在
Callout.calloutClass1中找到.clickForSomeAction按钮并模拟点击
office-fabric-ui 中有类似的组件(例如:DropDown、上下文菜单)在文档中呈现 HTML,而不是在当前组件 HTML 中呈现。
【问题讨论】:
标签: reactjs jestjs office-ui-fabric