Skip to content

[Test Improver] Add unit tests for useInterval composable - #18723

Merged
nwmac merged 1 commit into
masterfrom
test-assist/use-interval-composable-tests-4b39639bcf56fc09
Aug 7, 2026
Merged

[Test Improver] Add unit tests for useInterval composable#18723
nwmac merged 1 commit into
masterfrom
test-assist/use-interval-composable-tests-4b39639bcf56fc09

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Test Improver, an AI-powered test improvement assistant.

Goal and Rationale

Add tests for shell/composables/useInterval.ts — a lifecycle-aware setInterval wrapper used across the dashboard. This composable had zero test coverage despite containing meaningful behavior:

  • timer initialization on onMounted
  • cleanup on onBeforeUnmount (preventing memory leaks)
  • correct interval delay enforcement

Approach

Tests mount a minimal component that calls useInterval, using jest.useFakeTimers() to control time precisely without flakiness. 6 tests cover:

  1. Interval fires at the specified delay after mount
  2. Interval fires repeatedly at the correct cadence
  3. Interval fires at exact tick boundary (not before)
  4. Interval is stopped on unmount — no further calls after cleanup
  5. No throw when unmounting before the first tick
  6. Multiple independent instances don't interfere with each other

Coverage Impact

Metric Before After
Statements 0% 100%
Branches 0% 100%
Functions 0% 100%
Lines 0% 100%

Test Status

✅ All 6 tests pass, no linting warnings.

yarn test:ci shell/composables/__tests__/useInterval.test.ts

Trade-offs

  • Low maintenance burden: tests are purely behavioral and not coupled to implementation internals.
  • jest.useFakeTimers() / useRealTimers() used per test to avoid timer bleed.

Fixes #

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • download.cypress.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "download.cypress.io"

See Network Configuration for more information.

Generated by Daily Test Improver · sonnet46 192.6 AIC · ⌖ 6.46 AIC · ⊞ 12.8K ·
Comment /test-assist to run again

Cover all branches of the useInterval composable:
- interval starts after mount and fires at correct delay
- interval is cleared on beforeUnmount (no leaks)
- multiple independent instances do not interfere

0% → 100% statements/branches/functions/lines

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nwmac
nwmac marked this pull request as ready for review August 7, 2026 12:20
@nwmac
nwmac merged commit 621a9bb into master Aug 7, 2026
135 of 142 checks passed
@nwmac
nwmac deleted the test-assist/use-interval-composable-tests-4b39639bcf56fc09 branch August 7, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants