Test warns that I need to use `act` for user actions, then warns act is not configured if I do
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, react
调研方向
从 app/components/forms/inputs/date-time/tests/date-time.spec.tsx 开始,复现 await user.tab() 附近的警告。阅读 app/components/forms/inputs/date-time/date-time.tsx 和 app/components/forms/inputs/date/date.tsx,以跟踪日期选择器和表单更新。完成的标准是,有效输入测试可以执行 tab 和验证,且不会出现任何一个 act 警告。
由索引模型根据 Issue 内容生成。
描述
From my understanding, user actions do not need to be wrapped in act yet I'm still getting an error that state updates are happening outside of react for a datepicker component. When the user.tab() code is called below, that triggers a react-datepicker component to close and form state to update with validation.
Yet if I try to wrap the code inside act like it recommends, it says
Warning: The current testing environment is not configured to support act. All of our other act calls work fine so I think it's because it's "nesting" them since user events are already wrapped in act.
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. Learn more at https://reactjs.org/link/wrap-tests-with-act%s Manager
at Manager (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/@blueprintjs_core.js?v=19bc5f46:16758:24)
at Popover (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/@blueprintjs_core.js?v=19bc5f46:18798:5)
at div
at div
at InputOverlay (http://localhost:63315/app/components/overlays/overlays.tsx:165:32)
at SelectInput (http://localhost:63315/app/components/forms/inputs/selects/selects.tsx:285:3)
at div
at header
at CalendarHeader (http://localhost:63315/app/components/forms/inputs/date/date.tsx:118:3)
at div
at div
at div
at CalendarContainer (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/react-datepicker.js?v=19bc5f46:7267:16)
at Wrap (http://localhost:63315/app/components/forms/inputs/date/date.tsx:64:19)
at div
at ClickOutsideWrapper (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/react-datepicker.js?v=19bc5f46:7292:22)
at Calendar2 (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/react-datepicker.js?v=19bc5f46:9862:26)
at div
at div
at TabLoop2 (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/react-datepicker.js?v=19bc5f46:10477:26)
at Portal2 (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/react-datepicker.js?v=19bc5f46:10440:26)
at PopperComponent2 (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/react-datepicker.js?v=19bc5f46:10532:40)
at WithFloating (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/react-datepicker.js?v=19bc5f46:10515:35)
at DatePicker2 (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/react-datepicker.js?v=19bc5f46:10590:26)
at DateInput (http://localhost:63315/app/components/forms/inputs/date/date.tsx:222:3)
at div
at DateTimeInput (http://localhost:63315/app/components/forms/inputs/date-time/date-time.tsx:26:3)
at form
at FormProvider (http://localhost:63315/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/deps/chunk-OEVTHLDK.js?v=19bc5f46:114:11)
at Form (http://localhost:63315/app/components/forms/forms.tsx:59:3)
at DateTimeInputForm (http://localhost:63315/redacted/app/components/forms/inputs/date-time/tests/date-time.spec.tsx?import&browserv=1758221332900:19:3)
const DateTimeInputForm = ({ name, onSubmit, required, ...props }: DateTimeInputTestProps): React.JSX.Element => {
const schema = z.object({
[name]: zodDateTimeSchema({
required
})
})
const methods = useForm(schema)
return (
<Form methods={methods} onSubmit={onSubmit} schema={schema}>
<DateTimeInput name={name} required={required} {...props} />
</Form>
)
}
describe('inputs - date-time', () => {
it('does not error when valid', async () => {
const user = userEvent.setup()
render(<DateTimeInputForm includeSeconds label='Test' name='test' required />)
const inputs = document.querySelectorAll('input')
expect(inputs).toHaveLength(4)
await user.click(inputs[0])
await user.keyboard('2001-01-01')
await user.tab() // < removing this line avoids the error (but we have further logic after this we want to test)
expect(document.querySelector('input[class*="error"]')).toBeFalsy()
})
})
- 主要语言
- 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 于 8 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict mode可能重新可做 @suhailopensource 于 78 天前认领,目前没有进行中的 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 于 304 天前认领,目前没有进行中的 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 于 322 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
查看 testing-library/react-testing-library 的全部 Issue
相似的 Issue
-
🔧 in development
难度 2/5 1-3 小时 新手友好度 72/100
-
enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 85/100
-
p5.js 2.0+
难度 2/5 1-3 小时 新手友好度 62/100
processing/p5.js#9295 · 1 条评论 ·
维护者通常 3 天内回复
-
status: needs triage
难度 2/5 1-3 小时 新手友好度 78/100
mastra-ai/mastra#27210 · 1 条评论 ·
维护者通常 1 天内回复
-
content html
难度 2/5 1-3 小时 新手友好度 82/100