我有一個樣式按鈕:const MyButton = styled.button`...`我用onClick道具渲染它:<MyButton onClick={props.onClick}>A Button</MyButton>在我的按鈕測試文件中,我使用酶來測試onClick(樣式按鈕導入為“按鈕”):let counter = 0;const component = shallow( <Button onClick={() => counter++}> A Button </Button>);component.find(Button).simulate('click');在控制臺中我得到: Method “simulate” is meant to be run on 1 node. 0 found instead.使用調試時,component.debug()我看到元素是<styled.button>...</styled.button> 我嘗試更改我find()的接收styled.button甚至添加一個類名,我在調試時可以看到該類名,但似乎沒有得到元素。如何找到元素并在其上模擬事件?謝謝
模擬點擊樣式組件測試
牛魔王的故事
2021-06-23 17:13:22