-
-
Notifications
You must be signed in to change notification settings - Fork 53
test: silence act warnings #1552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughTest setup updates add a mock for Floating UI’s autoUpdate to run updates inside React’s act and suppress specific act-related console errors. Existing accessibility tag exports remain unchanged. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Test as Test
participant Setup as setupTests.ts
participant Mock as Mock autoUpdate
participant React as React act()
participant UI as Update Callback
Test->>Setup: Initialize test environment
Setup->>Mock: Install autoUpdate mock
Test->>Mock: autoUpdate(reference, floating, update)
alt update callback provided
Mock->>React: act(() => update())
React->>UI: invoke update()
UI-->>React: return
else no update provided
Note right of Mock: No act wrapping
end
Mock-->>Test: return no-op cleanup
Setup->>Setup: Patch console.error (filter act warnings)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Poem
✨ Finishing touches
🧪 Generate unit tests
Comment |
CoverageThis report compares the PR with the base branch. “Δ” shows how the PR affects each metric.
Coverage improved or stayed the same. Great job! Run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/setupTests.ts (3)
2-3: Optional: importactfromreact-dom/test-utilsfor version-agnostic stabilityRTL re-exports
act, but importing fromreact-dom/test-utilsavoids coupling to RTL’s re-export across versions.Apply:
-import { act } from '@testing-library/react'; +import { act } from 'react-dom/test-utils';If you’re on older React/RTL combos, confirm this import works across the repo before switching.
26-33: Narrow the console filter and preferjest.spyOnto preserve test-level spiesDirectly overriding
console.errorcan interfere with tests that spy/mute logs. Usejest.spyOnand a case-insensitive check; everything else forwards.Apply:
-const originalError = console.error; -console.error = (...args: unknown[]) => { - const firstArg = args[0]; - if (typeof firstArg === 'string' && firstArg.includes('not wrapped in act')) { - return; - } - originalError(...(args as Parameters<typeof originalError>)); -}; +const originalError = console.error.bind(console); +jest.spyOn(console, 'error').mockImplementation((...args: Parameters<typeof console.error>) => { + const firstArg = args[0]; + if (typeof firstArg === 'string' && /not wrapped in act/i.test(firstArg)) { + return; + } + originalError(...args); +});Optional: gate with an env flag if you want an escape hatch during debugging:
if (process.env.DEBUG_ACT_WARNINGS === '1') originalError(...args);
4-21: MockautoUpdateshould accept the optional 4thoptionsparamFound @floating-ui/react imports across the repo (e.g. src/core/primitives/Floater/index.tsx); no callers passing a 4th arg were found — make the mock arity‑flexible to match the upstream signature.
- autoUpdate: (reference: unknown, floating: unknown, update: () => void) => { - if (typeof update === 'function') { - act(() => { - update(); - }); - } - return () => {}; - } + autoUpdate: (...args: unknown[]) => { + const update = args[2] as (() => void) | undefined; + if (typeof update === 'function') { + act(() => update()); + } + return () => {}; + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/setupTests.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: coverage
- GitHub Check: build
Summary
Testing
npm testSummary by CodeRabbit