简体   繁体   English

酶单击组件内部的按钮组件内部

[英]Enzyme Click on Button Inside Component Inside Component

Im working on a React Javascript Storybook right now and Im trying to figure out how to get enzyme to click a button inside of a component inside a component. 我正在研究一本React Javascript故事书,我正在尝试弄清楚如何获得一种酶来单击组件内部组件的按钮。 So in other words this is the structure 换句话说,这就是结构

<Component 1>
   <Component 2>
    <Button>
   </Component 2>
</Component 1>

And I want to click on the Button inside of compoenent 2. So far I have this 我想单击组件2内的Button。到目前为止,我有这个

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/>;
});

Does anyone have any advice? 有人有建议吗? I should also add that as of current it does not find any buttons to click 我还应该补充一点,它目前没有找到要单击的按钮

As per Enzyme documentation you can use a React component constructor as your selector. 根据酶文档,您可以使用React组件构造函数作为选择器。 You can do something like this: 您可以执行以下操作:

output = mount(<Component1 />);
output.find(Component2).find(Button).simulate("click")

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

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