Skip to content

Conversation

@kotAPI
Copy link
Collaborator

@kotAPI kotAPI commented Sep 12, 2025

Summary

  • assert and silence Primitive.input warning when asChild has no child

Testing

  • npm test src/core/primitives/Radio/tests/Radio.test.tsx

Summary by CodeRabbit

  • Tests
    • Improved test coverage for the Radio component to verify a console warning is emitted when the asChild prop is used incorrectly.
    • Ensures the component still renders as expected while validating warning behavior.
    • Enhances confidence in developer-facing warnings without impacting end-user functionality.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 12, 2025

Walkthrough

Adds a console.warn spy and assertion to the RadioPrimitive asChild test in src/core/primitives/Radio/tests/Radio.test.tsx, verifying a specific warning message is logged when using asChild. Restores the mock after assertion and still checks the radio element renders in the document.

Changes

Cohort / File(s) Summary
Radio Primitive tests
src/core/primitives/Radio/tests/Radio.test.tsx
Extend asChild test: add Jest spy on console.warn, render with asChild, assert warning message "Primitive.input: asChild prop requires exactly one valid child element.", and restore mock; retain existing render assertion.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

automerge

Poem

I nudge the dial with gentle care,
A whisper: "Mind your single heir."
Console squeaks—warning aired—
One child only, nicely paired.
Thump-thump goes my reviewer’s heart,
Tests aligned, we hop to start. 🐇✅

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "test: capture radio warning" is concise, uses a conventional commit-style prefix, and accurately describes the primary change (adding an assertion to capture the Radio/Primitive.input console warning in tests), so it conveys the main intent to reviewers scanning history. It is specific to the changeset and not misleading or generic. The length and phrasing are appropriate for a test-focused PR.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kotapi/modify-test-to-expect-console-warning

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

Coverage

This report compares the PR with the base branch. “Δ” shows how the PR affects each metric.

Metric PR Δ
Statements 89.67% +0.00%
Branches 66.03% +0.00%
Functions 73.06% +0.00%
Lines 88.55% +0.00%

Coverage improved or stayed the same. Great job!

Run npm run coverage locally for detailed reports and target untested areas to raise these numbers.

@kotAPI kotAPI merged commit 1824f4a into main Sep 12, 2025
9 checks passed
@kotAPI kotAPI deleted the kotapi/modify-test-to-expect-console-warning branch September 12, 2025 14:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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/core/primitives/Radio/tests/Radio.test.tsx (2)

44-52: Make the warning assertion more robust and guarantee cleanup.

  • Match by substring to avoid brittleness if the message wording changes.
  • Assert it fires exactly once.
  • Use try/finally so the mock is restored even if an assertion fails.
-        const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
-        render(<RadioPrimitive {...baseProps} asChild />);
-        const radio = screen.getByRole('radio');
-        expect(radio).toBeInTheDocument();
-        expect(warnSpy).toHaveBeenCalledWith(
-            'Primitive.input: asChild prop requires exactly one valid child element.'
-        );
-        warnSpy.mockRestore();
+        const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
+        try {
+            render(<RadioPrimitive {...baseProps} asChild />);
+            const radio = screen.getByRole('radio');
+            expect(radio).toBeInTheDocument();
+            expect(warnSpy).toHaveBeenCalledWith(
+                expect.stringContaining('asChild prop requires exactly one valid child')
+            );
+            expect(warnSpy).toHaveBeenCalledTimes(1);
+        } finally {
+            warnSpy.mockRestore();
+        }

43-43: Rename test to reflect its behavior.

Clarify that it asserts a warning as well as rendering.

-it('supports asChild prop (renders without error)', () => {
+it('supports asChild prop: warns when missing child and still renders input', () => {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07797cf and 36a2421.

📒 Files selected for processing (1)
  • src/core/primitives/Radio/tests/Radio.test.tsx (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). (1)
  • GitHub Check: coverage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants