[Test Improver] Add unit tests for useInterval composable - #113
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[Test Improver] Add unit tests for useInterval composable#113github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Test the setInterval lifecycle composable that registers/clears an interval on component mount/unmount. - fn is not invoked before mount - fn fires after the specified delay once mounted - fn fires repeatedly on each tick - fn is not called before the delay elapses - interval is cleared on unmount (no further calls) - unmounting mid-interval prevents any call - table-driven cases validate count for short/long delays Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
21 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Test Improver, an automated AI assistant focused on improving test coverage.
Goal and Rationale
shell/composables/useInterval.tshad no test coverage. It registers asetIntervalononMountedand clears it ononBeforeUnmount— a lifecycle-driven side effect that is easy to misuse (e.g. timer leaks, interval not cleared on unmount). Testing this verifies correct lifecycle integration and that the cleanup guard works properly.Approach
Each test mounts/unmounts a minimal
defineComponentharness that callsuseInterval, then advances fake timers to observe call counts. This isolates the composable without requiring a real component.Tests (8 total):
setInterval, not eagerlyonMountedsetInterval(notsetTimeout) behaviordelay - 1msclearIntervalguard inonBeforeUnmountCoverage Impact
useInterval.tsmoves from 0 % → ~100 % statement/branch coverage (all branches: mounted callback, unmount guard,if (interval.value)check).Trade-offs
jest.useFakeTimers()per-test to avoid wall-clock delays.defineComponentharness keeps tests self-contained and avoids mocking Vue internals.Reproducibility
Test Status
✅ All 8 tests pass. ESLint reports 0 warnings/errors.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
download.cypress.ioSee Network Configuration for more information.