首页 > 解决方案 > 没有测试文件,但 NextJs 仍然显示这个`测试时,导致 React 状态更新的代码应该被包装到 act(...) 中:`

问题描述

我想知道这个错误消息是从哪里来的。我扫描了所有与测试相关的文件。**.test.tsx、**.test.js 和 *.spec.tsx 等。知道为什么即使项目中没有测试也会出现这种情况。

笔记:


When testing, code that causes React state updates should be wrapped into act(...):

act(() => {
  /* fire events that update state */
});
/* assert on the output */

This ensures that you're testing the behavior the user would see in the browser.

标签: reactjsnext.js

解决方案


推荐阅读