Skip to content

Conversation

@kotAPI
Copy link
Collaborator

@kotAPI kotAPI commented Sep 12, 2025

Summary

  • mock Floating UI autoUpdate to run synchronously
  • filter noisy React "not wrapped in act" warnings during tests

Testing

  • npm test

Summary by CodeRabbit

  • Tests
    • Improved test reliability by ensuring UI update callbacks run within React’s act during tests, reducing flakiness and timing issues.
    • Silenced noisy “not wrapped in act” warnings in test output for cleaner, more readable logs.
    • Added safe no-op cleanup for mocked updates to stabilize test runs.
    • No changes to application behavior or public APIs; existing accessibility test tags remain unchanged.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 12, 2025

Walkthrough

Test 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

Cohort / File(s) Summary of modifications
Test Setup
src/setupTests.ts
Import act from @testing-library/react; mock @floating-ui/react.autoUpdate to call update within act and return a no-op cleanup; wrap console.error to ignore “not wrapped in act” warnings; retain ACCESSIBILITY_TEST_TAGS export.

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)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "test: silence act warnings" is concise, follows conventional commit style, and directly describes the primary intent of the changeset (suppressing noisy React "not wrapped in act" warnings in tests). It is specific enough for a teammate scanning PR history to understand the main purpose and avoids unnecessary detail. Omitting the Floating UI autoUpdate mock is acceptable because PR titles need not enumerate every test fixture tweak.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

I twitch my nose at tests that squeak,
Wrap updates swift, not weak—so sleek!
With act we hop, no warnings cry,
Our console calm, the logs drift by.
A silent warren, green and bright,
Mocked winds guide Floating UI’s flight.

✨ 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/fix-test-updates-not-wrapped-in-act

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 de964ba into main Sep 12, 2025
9 checks passed
@kotAPI kotAPI deleted the kotapi/fix-test-updates-not-wrapped-in-act branch September 12, 2025 14:47
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 (3)
src/setupTests.ts (3)

2-3: Optional: import act from react-dom/test-utils for version-agnostic stability

RTL re-exports act, but importing from react-dom/test-utils avoids 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 prefer jest.spyOn to preserve test-level spies

Directly overriding console.error can interfere with tests that spy/mute logs. Use jest.spyOn and 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: Mock autoUpdate should accept the optional 4th options param

Found @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

📥 Commits

Reviewing files that changed from the base of the PR and between 1824f4a and 46af389.

📒 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

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