[英]Enzyme Click on Button Inside Component Inside Component
我正在研究一本React Javascript故事書,我正在嘗試弄清楚如何獲得一種酶來單擊組件內部組件的按鈕。 換句話說,這就是結構
<Component 1>
<Component 2>
<Button>
</Component 2>
</Component 1>
我想單擊組件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/>;
});
有人有建議嗎? 我還應該補充一點,它目前沒有找到要單擊的按鈕
根據酶文檔,您可以使用React組件構造函數作為選擇器。 您可以執行以下操作:
output = mount(<Component1 />);
output.find(Component2).find(Button).simulate("click")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.