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

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

使用材質(zhì) UI 和反應(yīng)測(cè)試庫(kù)時(shí)從對(duì)話框測(cè)試 onClose 回調(diào)?

使用材質(zhì) UI 和反應(yīng)測(cè)試庫(kù)時(shí)從對(duì)話框測(cè)試 onClose 回調(diào)?

瀟湘沐 2021-12-02 14:59:24
我目前正在嘗試在我的 React 應(yīng)用程序上獲得完整的測(cè)試覆蓋率,但是在嘗試測(cè)試來自 Material UI 組件的回調(diào)事件參數(shù)時(shí),我遇到了笑話。我認(rèn)為通過測(cè)試轉(zhuǎn)義事件我可以覆蓋onClose參數(shù),但它仍然顯示為未經(jīng)測(cè)試。該測(cè)試的示例:function renderWithRedux(  ui: any,  startingState: any = initialState,  store?: any) {  if (!store) {    store = createStore(reducer, startingState);  }  return {    ...render(<Provider store={store}>{ui}</Provider>),    // adding `store` to the returned utilities to allow us    // to reference it in our tests (just try to avoid using    // this to test implementation details).    store,  };}test("Should close the dialog on exit event eg esc key pressed", () => {  const { container, queryByTestId } = renderWithRedux(    <PermissionGroupList />,    permissionGroupCat  );  fireEvent(    queryByTestId("add-group"),    new MouseEvent("click", {      bubbles: true,      cancelable: true,    })  );  let dialogBox = queryByTestId("add-group-dialog");  // Check that the dialog is open.  expect(dialogBox).toBeTruthy();  // Check that the dialog it closes.  fireEvent.keyDown(document.body, {    key: "Escape",    keyCode: 27,    which: 27  })  setTimeout(() => {    // Try to re get the element.    dialogBox = queryByTestId("add-group-dialog");    expect(dialogBox).toBeNull();  }, 500);})將綁定closeDialog方法傳遞給子組件時(shí)出現(xiàn)相同或類似的問題。它似乎未經(jīng)測(cè)試。我將如何測(cè)試這個(gè)/如果它觸發(fā)方法(在子組件上),它是否會(huì)被子組件的測(cè)試覆蓋,我還沒有創(chuàng)建子組件測(cè)試。正如您在上面的屏幕截圖中所看到的,這兩行都未經(jīng)測(cè)試,所以我如何用我的測(cè)試來覆蓋這些。我正在使用 react-testing-library 和 jest --coverage 與 redux 和 react-redux。
查看完整描述

2 回答

?
海綿寶寶撒

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

我建議不要?jiǎng)?chuàng)建箭頭函數(shù)作為道具。以下是對(duì)缺點(diǎn)和替代方法的更詳細(xì)說明:https : //medium.com/@oleg008/arrow-functions-in-react-f782d11460b4

這也將使您的測(cè)試涵蓋這些道具。盡管您可能還需要測(cè)試handleGroupDialog是否調(diào)用了類方法。你可以用間諜來做到這一點(diǎn):https : //remarkablemark.org/blog/2018/06/13/spyon-react-class-method/

大衛(wèi)也說得對(duì)!您將需要使用 done 方法或?qū)⒛臏y(cè)試轉(zhuǎn)換為異步并等待。


查看完整回答
反對(duì) 回復(fù) 2021-12-02
?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊

您在同步測(cè)試中運(yùn)行的異步代碼。如果您setTimeout在測(cè)試中使用,那么您需要傳入一個(gè)done()函數(shù),然后在最后一個(gè)異步事件完成時(shí)調(diào)用它。

https://jestjs.io/docs/en/asynchronous


查看完整回答
反對(duì) 回復(fù) 2021-12-02
  • 2 回答
  • 0 關(guān)注
  • 167 瀏覽
慕課專欄
更多

添加回答

舉報(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)