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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何測(cè)試在內(nèi)部呈現(xiàn)子元素的組件?

如何測(cè)試在內(nèi)部呈現(xiàn)子元素的組件?

富國(guó)滬深 2021-06-09 09:04:39
我有以下組件:export default function Button({ className, children, ...otherProps }) {  return (    <button className={'button} {...otherProps}>      {children}    </button>  );}在父組件中,我在里面?zhèn)鬟f了這樣的道具和標(biāo)簽:<Button className={test-button} onClick={this.removeItems} >    <i className="fa fa-trash-alt" /> Remove all items</Button>我無(wú)法理解如何正確地對(duì)這些組件進(jìn)行單元測(cè)試。例如,我想測(cè)試onClick單擊組件時(shí)調(diào)用的函數(shù)。我寫(xiě)了這樣一個(gè)測(cè)試:const buttonFunc = jest.fn();    const props = {        children: {        className: "test",        onClick: buttonFunc,    }};let wrapper;beforeEach(() => {    wrapper = shallow(<Button {...props} />);});test('click on switch button', () => {    wrapper.simulate('click');    expect(buttonFunc).toHaveBeenCalledTimes(1);    console.log(wrapper.debug())});但我有一個(gè)錯(cuò)誤預(yù)期模擬函數(shù)已被調(diào)用一次,但被調(diào)用了零次。
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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