React act() warning persists with latest versions (React 18.3.1 + RTL 16.3.0 + Vitest 2.1.0)
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 冷清
- 技术栈
- javascript, react, typescript
- 领域
- frontend, testing-qa
调研方向
未指定 repository 文件或测试。首先使用所列出的 React、React Testing Library、Vitest、Node 和 jsdom 版本运行最小复现,然后追踪产生该警告的测试环境设置。完成的标准是确定一个可复现的兼容性原因,并记录或验证一个能够移除该警告且不会破坏测试的 fix。
由索引模型根据 Issue 内容生成。
描述
Summary
The "Warning: The current testing environment is not configured to support act(...)" warning persists with the latest versions of React, React Testing Library, and Vitest as of January 2025.
Environment
- React: 18.3.1
- React DOM: 18.3.1
- @testing-library/react: 16.3.0
- Vitest: 2.1.0
- Node: 20+
- Environment: jsdom
Related Issues
This appears to be a continuation of:
- #1336 (June 2024) - Same warning with RTL v16
- #1338 (June 2024) - Vitest + RTL + userEvent warnings
- #1061 (2022) - Original issue, claimed resolved but persists
Problem Description
Despite following all documented solutions and having the latest versions:
- ✅ React 18.3.1+ (required version)
- ✅ Single React version in dependency tree (verified with
npm ls react) - ✅ Latest @testing-library/react (16.3.0)
- ✅ Properly using
act()from @testing-library/react - ✅ Removed manual
IS_REACT_ACT_ENVIRONMENTsettings (as docs suggest these are ineffective in React 18.3.1+)
The warning still appears when running tests with Vitest.
Minimal Reproduction
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
const TestComponent = () => {
const [loading, setLoading] = useState(false);
const handleClick = async () => {
setLoading(true);
await fetch('/api/test');
setLoading(false);
};
return (
<button onClick={handleClick}>
{loading ? 'Loading...' : 'Click me'}
</button>
);
};
describe('TestComponent', () => {
it('should handle async state updates', async () => {
global.fetch = vi.fn().mockResolvedValue({ ok: true });
render(<TestComponent />);
const button = screen.getByText('Click me');
await act(async () => {
fireEvent.click(button);
await waitFor(() => {
expect(screen.getByText('Loading...')).toBeInTheDocument();
});
});
// Warning appears here despite proper act() usage
});
});
Expected Behavior
No warnings when using act() properly with supported versions.
Actual Behavior
Warning: The current testing environment is not configured to support act(...)
Question for Maintainers
- Is this a known limitation of the Vitest + React 18.3.1+ combination?
- Is there a timeline for resolving this compatibility issue?
- Should these warnings be considered acceptable/ignorable with the current tech stack?
Tests function correctly despite the warnings, but they create noise in CI/CD pipelines and developer workflows.
Additional Context
Multiple developers have reported this same issue across different projects with identical tech stacks, suggesting this is a systematic compatibility problem rather than individual configuration issues.
- 主要语言
- JavaScript
- 星标
- 19.7k
- 派生
- 1.2k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
testing-library/react-testing-library 的其他 Issue
-
fireEvent.select does not wrap its automatic native focus in act可能已有人在做 @sergioperezcheco 于 15 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict mode可能重新可做 @suhailopensource 于 85 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
testing-library/react-testing-library#1466 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 30/100
testing-library/react-testing-library#1459 · 2 条评论 ·
-
perf: optimize container lookup with early exit可能重新可做 @Ch-Abhinav-Chowdary 于 311 天前认领,目前没有进行中的 PR。 未关闭
难度 1/5 1 小时以内 新手友好度 35/100
testing-library/react-testing-library#1430 · 1 条评论 ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)可能已有人在做 @swarnim02 于 329 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
查看 testing-library/react-testing-library 的全部 Issue
相似的 Issue
-
bug priority: low
难度 1/5 1 小时以内 新手友好度 88/100
sandialabs/sceptre-phenix#464 ·
维护者通常 6 天内回复
-
难度 1/5 1 小时以内 新手友好度 66/100
hemilabs/token-list#124 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
feature
难度 2/5 1-3 小时 新手友好度 82/100
juice-shop/juice-shop#3702 ·
维护者通常 1 天内回复
-
🐛 BUG: Avatar stack on post card renders above the sticky header when scrolling可能已有人在做 @idoshamun 今天认领。 未关闭Type: Bug
难度 2/5 1-3 小时 新手友好度 68/100
dailydotdev/daily#2163 ·
维护者通常 1 天内回复