簡體   English   中英

使用 Jest + React 測試庫對測試中 Provider 的更新未包含在 act(...) 中

[英]An update to Provider inside a test was not wrapped in act(…) with Jest + React Testing Library

我正在嘗試使用 React 測試庫和 Jest 測試我的 React 應用程序,但我總是遇到以下錯誤。

An update to StoreProvider inside a test was not wrapped in act(...)

我在測試中嘗試了很多方法,例如 put act() function 但無法刪除警告並獲得正確的結果。

這是一個證明問題的簡化項目: https://codesandbox.io/s/adoring-haslett-6rq34?file=/src/PageContent.test.js

謝謝你的幫助。

這是一個有效的解決方案。

https://github.com/testing-library/react-testing-library/issues/641#event-3244842083

我必須等待一個元素

const { findByText } = render(<App />)
expect(await findByText('STATUS = 0')).toBeInTheDocument();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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