test(query-devtools/Explorer): add test for 'CopyButton' error state on clipboard failure#10734
Conversation
…on clipboard failure
📝 WalkthroughWalkthroughThe test suite now wraps each test with ChangesExplorer test suite clipboard handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
View your CI Pipeline Execution ↗ for commit a9ec428
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version PreviewNo changeset entries found. Merging this PR will not cause a version bump for any packages. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/query-devtools/src/__tests__/Explorer.test.tsx`:
- Around line 26-29: The afterEach teardown currently calls vi.useRealTimers()
and queryClient.clear() but does not restore mocks or any replaced globals,
which lets per-test stubs like console.error and navigator leak; update the
afterEach (the same block containing vi.useRealTimers() and queryClient.clear())
to call vi.restoreAllMocks() and vi.resetAllMocks() to restore spies/stubs and
mocks, and if tests replace navigator directly ensure you restore the original
navigator (e.g., save originalNavigator in beforeEach and reassign it in
afterEach or delete the stubbed global navigator) so console.error and navigator
stubs do not persist across tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 81c8b79a-e453-4c81-bc0a-9e6d04ad22d9
📒 Files selected for processing (1)
packages/query-devtools/src/__tests__/Explorer.test.tsx
| afterEach(() => { | ||
| vi.useRealTimers() | ||
| queryClient.clear() | ||
| }) |
There was a problem hiding this comment.
Harden teardown to avoid cross-test mock/global leakage (Line 27).
With fake timers enabled globally and new per-test spies/stubs, teardown should also restore mocks/globals; otherwise console.error and navigator stubs can bleed into later tests.
Suggested patch
afterEach(() => {
vi.useRealTimers()
+ vi.restoreAllMocks()
+ vi.unstubAllGlobals()
queryClient.clear()
})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| afterEach(() => { | |
| vi.useRealTimers() | |
| queryClient.clear() | |
| }) | |
| afterEach(() => { | |
| vi.useRealTimers() | |
| vi.restoreAllMocks() | |
| vi.unstubAllGlobals() | |
| queryClient.clear() | |
| }) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/query-devtools/src/__tests__/Explorer.test.tsx` around lines 26 -
29, The afterEach teardown currently calls vi.useRealTimers() and
queryClient.clear() but does not restore mocks or any replaced globals, which
lets per-test stubs like console.error and navigator leak; update the afterEach
(the same block containing vi.useRealTimers() and queryClient.clear()) to call
vi.restoreAllMocks() and vi.resetAllMocks() to restore spies/stubs and mocks,
and if tests replace navigator directly ensure you restore the original
navigator (e.g., save originalNavigator in beforeEach and reassign it in
afterEach or delete the stubbed global navigator) so console.error and navigator
stubs do not persist across tests.
size-limit report 📦
|
🎯 Changes
Extend
Explorer.test.tsxwith a test for the error path ofCopyButton— whennavigator.clipboard.writeTextrejects, the button'saria-labelshould switch to the error state and the failure should be logged viaconsole.error.Also enable fake timers globally in
beforeEach/afterEachso promise rejection microtasks can be flushed deterministically withvi.advanceTimersByTimeAsync(0)(without affecting any existing case).Added cases (
action menu, 1):should switch the copy button to an error state when clipboard write fails— stubsnavigator.clipboard.writeTextwithmockRejectedValue, silencesconsole.errorviavi.spyOn, and asserts both the post-rejectionaria-labeland theconsole.errorcall shape.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit