[英]TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner')
我有一個 npm monorepo,其中包含 web 個應用程序 (React 18)、移動應用程序 (React-Native 0.71/React 18) 和共享庫。 我還使用 npm 覆蓋來修復 React 版本,這沒有改變。 一些更新后,當我運行 Jest 測試時,我的一個項目中出現以下錯 ...
[英]TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner')
我有一個 npm monorepo,其中包含 web 個應用程序 (React 18)、移動應用程序 (React-Native 0.71/React 18) 和共享庫。 我還使用 npm 覆蓋來修復 React 版本,這沒有改變。 一些更新后,當我運行 Jest 測試時,我的一個項目中出現以下錯 ...
[英]react-test-renderer test failing TypeError: Cannot read properties of undefined (reading 'current')
我正在嘗試使用 react-test-renderer 進行單元測試,但我似乎無法通過測試,即使我正在測試的底層組件有效。 有人可以告訴我我做錯了什么這是組件的代碼 這是測試代碼 這些是我得到的錯誤 我嘗試運行 yarn test 但它失敗了。 這里編輯的是animation文件的代碼 ...
[英]Jest SyntaxError: Unexpected token '<' React
我已經能夠測試 ts 文件,但是當我嘗試為 tsx 文件編寫測試時,我得到了錯誤: const rendered = (0, _reactTestRenderer.create)(); ^ SyntaxError: 意外的標記 '<' 測試文件: package.json jestS ...
[英]getById is not a function
當我嘗試模擬點擊時,主題行中出現錯誤。 我的整個測試文件: 該錯誤專門指向getById : 類型錯誤:getById 不是 function ...
[英]Jest snapshot test logs errors messages BUT app renders and seems to function correctly
為了熟悉前端測試,我最近開始使用 Jest 快照庫。 我遇到的一個問題是它的錯誤信息。 盡管應用程序看似正常運行,但我收到錯誤消息。 例如: 我的應用程序有一個名為<NavBar/>的導航欄,與大多數導航欄一樣,它包含鏈接。 我使用react-router-dom來創建鏈接。 這是帶有 ...
[英]jest test is not exiting after test passes with react-test-renderer
我使用 React Native 0.68.2/jest 29.0 對一個簡單組件進行了 toMatchSnapshot 測試。 這是組件SysError : 這是 SysError.test.js: 在yarn test --detectOpenHandle之后,測試通過但不會自行退出。 這是組件 ...
[英]react jest test return error when test component with properties
我想知道為什么我的最后一個測試失敗了-> it("cron 輸入應該在屬性中有一個通過的值"。我嘗試在沒有和有屬性的情況下測試我的反應組件,前兩個測試通過但最后一個給了我一個錯誤。就像我的組件不接受我傳遞的屬性的值一樣。 這是測試的 output 錯誤: 這是我的反應組件: 這是我的測試文件。 ...
[英]Jest Snapshot Testing Wait till Component Renders
在使用異步獲取操作測試 React 組件時,我覺得我遺漏了一些東西。 我有一個像這樣的以下組件...... 我想創建以下測試。 我遇到的問題是在拍攝快照時數據尚未返回。 無論采用哪種方法,我都會遇到如下警告問題 或者它總是顯示正在獲取數據... 我使用了來自 @testing-library/rea ...
[英]Infinite loop in useEffect after an API mock in Jest
在我目前正在處理的組件中看到一些奇怪的東西。 因此,我有一個服務器端分頁表,在每次 API 調用中,我都將新記錄推送到現有數組。 我正在使用fetchBaseQuery進行 API 調用。 實現它的代碼 測試用例 根據我的理解,如果我們在useEffect掛鈎中使用數組作為依賴項,則可能會 ...
[英]React test Renderer - fails test after onClick
我有這個組件: 我有這個測試套件: 前 3 個測試正常通過,但最后一個在 expect(h2).toEqual('light'); 上失敗。 我很困惑為什么會發生這種情況,因為在手動測試時我看到組件按預期運行,因此在 onClick 事件之后更改了文本和圖標。 ...
[英]@testing-library/react render Error: `target` and `targetRef` props are `undefined`, it' required to use one of them
我正在嘗試為使用來自@fluentui/react-northstar的Dialog的自定義反應組件編寫單元測試,當我嘗試從測試中渲染組件時出現錯誤: 編碼: //testutils.tsx import { render } from '@testing-library/react'; imp ...
[英]createRoot(...): Target container is not a DOM element in React Test file
我在我的項目中使用 React-18.0.0,在測試文件中出現以下錯誤 createRoot(...):目標容器不是 DOM 元素。 我的測試文件是:import ReactDOM from 'react-dom/client'; import { render, screen } from "@t ...
[英]How to test React Number Format
我在這里使用了 React Number Format package,我想測試它的 onChange 事件,但出現錯誤,有人可以幫我解決這個問題。 我在下面給出了我的測試代碼和組件。 在代碼的 fireEevent 方法中,它一直說 Argument of type 'HTMLElement | ...
[英]How to test tr(table row) has onclick and style={{ cursor: "pointer" }} in react testing library
我這樣試過 錯誤是屬性“onclick 在類型字符串上不存在”,並且在測試時顯示索引的值。 如何測試這個? ...
[英]How to test a React component, that returns an other component?
我有一個這樣的 React 組件: 如何創建一個react-test笑話測試,檢查給定的數據,返回什么組件? 我試圖這樣解決它: 它給了我一個錯誤,因為queryByTestId('custom-element-one')返回 null。 我懷疑,這是因為OtherComponent本身不是一個元 ...
[英]How correctly write Jest test for avoid act() warning?
useEffect 通常使用 Promises 來更新 state。 此更新會開玩笑地發出長時間警告: Warning: An update to null inside a test was not wrapped in act(...). 對於這種情況如何正確編寫 Jest Test? 活生 ...
[英]Jest test passes but .. has console message You are trying to access a property or method of the Jest environment after it has been torn down
我的測試通過但有一個控制台 refrenceError: 在 Jest 環境被拆除后,您正試圖訪問它的屬性或方法。 測試: 有任何想法嗎? 這將檢查 async/await api 調用的響應。 ...
[英]How to write test cases for Select Box onChange Method in React Testing Library?
我有一個 Select 框,並通過onChange事件將數據設置在 state 中。 請看下面的代碼。 任何人都可以幫助我在 React 測試庫中為這個onChange事件編寫案例。 ...
[英]How to test react component with onClick function Jest/React testing library
我試圖在其中一個測試中達到 100% 的覆蓋率,它突出顯示了設置組件狀態的 onClick 函數:這是組件: 我有一個具有 onClick 功能的按鈕,如下所示,該按鈕是從一組對象映射進來的。 此按鈕單擊並設置所單擊按鈕的活動索引,因為這是一個按鈕組。 我將如何在 jest/react-tes ...
[英]<Suspense /> and React.createElement
在 .tsx 中,這按預期工作: 但是 .ts 中假定的等效項不起作用: 嘗試呈現 SuspenseComponentTS 時的錯誤消息如下: 打印到控制台,它們似乎是等效的: expect(SuspenseComponentTSX).toEqual("") : expect( ...