gpt4 book ai didi

javascript - enzyme 单击组件​​内的按钮 组件内

转载 作者:行者123 更新时间:2023-12-03 00:02:33 25 4
gpt4 key购买 nike

我现在正在编写 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com