第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

模擬點擊樣式組件測試

模擬點擊樣式組件測試

牛魔王的故事 2021-06-23 17:13:22
我有一個樣式按鈕:const MyButton = styled.button`...`我用onClick道具渲染它:<MyButton onClick={props.onClick}>A Button</MyButton>在我的按鈕測試文件中,我使用酶來測試onClick(樣式按鈕導(dǎo)入為“按鈕”):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.使用調(diào)試時,component.debug()我看到元素是<styled.button>...</styled.button> 我嘗試更改我find()的接收styled.button甚至添加一個類名,我在調(diào)試時可以看到該類名,但似乎沒有得到元素。如何找到元素并在其上模擬事件?謝謝
查看完整描述

2 回答

?
蠱毒傳說

TA貢獻(xiàn)1895條經(jīng)驗 獲得超3個贊

當(dāng)component.find(Button)您試圖在按鈕內(nèi)找到一個按鈕時,您的示例中并非如此。去吧:


let counter = 0;

const component = shallow(

     <Button onClick={() => counter++}>

          A Button

     </Button>

);

component.simulate('click');


查看完整回答
反對 回復(fù) 2021-06-24
?
桃花長相依

TA貢獻(xiàn)1860條經(jīng)驗 獲得超8個贊

如果您正在測試 MyButton,那么您應(yīng)該導(dǎo)入它并使用它:


import MyButton from './some-button';

const component = shallow(<MyButton />);

component.find(MyButton).simulate('click');

但是,您是在使用未導(dǎo)入的還是在實際代碼中使用的?


查看完整回答
反對 回復(fù) 2021-06-24
  • 2 回答
  • 0 關(guān)注
  • 282 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號