cost 411 ms
類型錯誤:無法讀取未定義的屬性(讀取“ReactCurrentOwner”)

[英]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文件的代碼 ...

getById 不是 function

[英]getById is not a function

當我嘗試模擬點擊時,主題行中出現錯誤。 我的整個測試文件: 該錯誤專門指向getById : 類型錯誤:getById 不是 function ...

Jest 快照測試記錄錯誤消息,但應用程序正確呈現並且似乎 function

[英]Jest snapshot test logs errors messages BUT app renders and seems to function correctly

為了熟悉前端測試,我最近開始使用 Jest 快照庫。 我遇到的一個問題是它的錯誤信息。 盡管應用程序看似正常運行,但我收到錯誤消息。 例如: 我的應用程序有一個名為<NavBar/>的導航欄,與大多數導航欄一樣,它包含鏈接。 我使用react-router-dom來創建鏈接。 這是帶有 ...

當測試具有屬性的組件時反應笑話測試返回錯誤

[英]react jest test return error when test component with properties

我想知道為什么我的最后一個測試失敗了-> it("cron 輸入應該在屬性中有一個通過的值"。我嘗試在沒有和有屬性的情況下測試我的反應組件,前兩個測試通過但最后一個給了我一個錯誤。就像我的組件不接受我傳遞的屬性的值一樣。 這是測試的 output 錯誤: 這是我的反應組件: 這是我的測試文件。 ...

Jest 快照測試等到組件渲染

[英]Jest Snapshot Testing Wait till Component Renders

在使用異步獲取操作測試 React 組件時,我覺得我遺漏了一些東西。 我有一個像這樣的以下組件...... 我想創建以下測試。 我遇到的問題是在拍攝快照時數據尚未返回。 無論采用哪種方法,我都會遇到如下警告問題 或者它總是顯示正在獲取數據... 我使用了來自 @testing-library/rea ...

Jest 中的 API 模擬后 useEffect 中的無限循環

[英]Infinite loop in useEffect after an API mock in Jest

在我目前正在處理的組件中看到一些奇怪的東西。 因此,我有一個服務器端分頁表,在每次 API 調用中,我都將新記錄推送到現有數組。 我正在使用fetchBaseQuery進行 API 調用。 實現它的代碼 測試用例 根據我的理解,如果我們在useEffect掛鈎中使用數組作為依賴項,則可能會 ...

反應測試渲染器 - onClick 后測試失敗

[英]React test Renderer - fails test after onClick

我有這個組件: 我有這個測試套件: 前 3 個測試正常通過,但最后一個在 expect(h2).toEqual('light'); 上失敗。 我很困惑為什么會發生這種情況,因為在手動測試時我看到組件按預期運行,因此在 onClick 事件之后更改了文本和圖標。 ...

@testing-library/react 渲染錯誤:`target` 和 `targetRef` 屬性是 `undefined`,需要使用其中之一

[英]@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(...): 目標容器不是 React 測試文件中的 DOM 元素

[英]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 ...

如何測試 React 數字格式

[英]How to test React Number Format

我在這里使用了 React Number Format package,我想測試它的 onChange 事件,但出現錯誤,有人可以幫我解決這個問題。 我在下面給出了我的測試代碼和組件。 在代碼的 fireEevent 方法中,它一直說 Argument of type 'HTMLElement | ...

如何測試返回另一個組件的 React 組件?

[英]How to test a React component, that returns an other component?

我有一個這樣的 React 組件: 如何創建一個react-test笑話測試,檢查給定的數據,返回什么組件? 我試圖這樣解決它: 它給了我一個錯誤,因為queryByTestId('custom-element-one')返回 null。 我懷疑,這是因為OtherComponent本身不是一個元 ...

Jest 測試通過但是.. 有控制台消息您正在嘗試在 Jest 環境被拆除后訪問它的屬性或方法

[英]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 調用的響應。 ...

如何使用 onClick 函數 Jest/React 測試庫測試 React 組件

[英]How to test react component with onClick function Jest/React testing library

我試圖在其中一個測試中達到 100% 的覆蓋率,它突出顯示了設置組件狀態的 onClick 函數:這是組件: 我有一個具有 onClick 功能的按鈕,如下所示,該按鈕是從一組對象映射進來的。 此按鈕單擊並設置所單擊按鈕的活動索引,因為這是一個按鈕組。 我將如何在 jest/react-tes ...


 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM