-
-
Notifications
You must be signed in to change notification settings - Fork 53
Silence Primitive asChild warning in tests #1557
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
WalkthroughAdds a console.warn filter in test setup to silence messages containing "asChild prop requires exactly one valid child element" while forwarding others. Retains existing console.error suppression for "not wrapped in act". Changes are confined to src/setupTests.ts and do not alter exported APIs. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Jest as Test Runner
participant Setup as setupTests.ts
participant Console as console
participant App as Test Subject
Jest->>Setup: import/setup
Setup->>Console: store original warn/error
Setup->>Console: override console.warn and console.error
App->>Console: console.warn("asChild prop requires exactly one valid child element")
Console->>Console: check message contains substring
alt matches filter
Console-->>App: suppressed (no output)
else forwards
Console->>Console: call originalWarn(...args)
end
App->>Console: console.error("not wrapped in act(...)")
Console->>Console: check message contains substring
alt matches filter
Console-->>App: suppressed (no output)
else forwards
Console->>Console: call originalError(...args)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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 (2)
src/setupTests.ts (2)
35-44: Make the wrapper idempotent to avoid stacking across test files.setupFilesAfterEnv can run per test file; guarding prevents multiple nested wrappers.
Apply:
-// Silence specific console warnings that are noisy in tests -const originalWarn = console.warn; -console.warn = (...args: unknown[]) => { - const firstArg = String(args[0]); - if (firstArg.includes('asChild prop requires exactly one valid child element')) { - return; - } - originalWarn(...(args as Parameters<typeof originalWarn>)); -}; +// Silence specific console warnings that are noisy in tests (idempotent) +if (!(console.warn as any).__asChildSilenced) { + const originalWarn = console.warn.bind(console); + const wrapped = (...args: unknown[]) => { + const firstArg = String(args[0]); + if (firstArg.includes('asChild prop requires exactly one valid child element')) { + return; + } + originalWarn(...(args as Parameters<typeof originalWarn>)); + }; + (wrapped as any).__asChildSilenced = true; + console.warn = wrapped as any; +}
38-41: Match across all args (case-insensitive) to reduce false negatives.Some libraries pass template strings + args; scanning all args makes the filter more robust.
Apply:
- const firstArg = String(args[0]); - if (firstArg.includes('asChild prop requires exactly one valid child element')) { + const haystack = args.map((a) => String(a)).join(' ').toLowerCase(); + if (haystack.includes('aschild prop requires exactly one valid child element')) {
📜 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: Build
- GitHub Check: coverage
🔇 Additional comments (1)
src/setupTests.ts (1)
35-44: Targeted suppression looks good.Only the specific Primitive asChild warning is silenced; other warnings are forwarded. Matches existing console.error pattern and keeps test output clean.
Summary by CodeRabbit