我现在正在编写 React Javascript Storybook,我正在尝试找出如何让 enzyme 单击组件内组件内的按钮。换句话说,这就是结构
<Component 1>
<Component 2>
<Button>
</Component 2>
</Component 1>
我想单击组件 2 内的按钮。到目前为止我已经有了这个
storesOf("Press the button",module).add("Button press:,() => {
let output;
specs(() => describe('clicked',function () {
it("Should do the thing",function () {
output = mount(<Component 1/>);
output.find("Button").at(0).simulate("click")
})
}));
const Inst = () => output.instance();
return <Inst/>;
});
有人有什么建议吗?我还应该补充一点,截至目前,它没有找到任何可以单击的按钮
最佳答案
根据 Enzyme documentation您可以使用 React 组件构造函数作为选择器。你可以这样做:
output = mount(<Component1 />);
output.find(Component2).find(Button).simulate("click")
关于javascript - enzyme 单击组件内的按钮 组件内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55110656/