使用材質(zhì) UI 和反應(yīng)測(cè)試庫(kù)時(shí)從對(duì)話框測(cè)試 onClose 回調(diào)?
我目前正在嘗試在我的 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。
查看完整描述