Skip to content

Conversation

@gitauto-ai
Copy link
Contributor

@gitauto-ai gitauto-ai bot commented Jan 19, 2026

Resolves #608

Summary

Add comprehensive unit tests for utils/get-random-item.ts to cover happy paths, edge cases, and error scenarios with deterministic assertions.

Test Patterns

  • Selects a valid element from a non-empty array.
  • Deterministic selection by mocking Math.random (e.g., 0, mid-range, and near-1) to hit boundary indices (0 and length - 1).
  • Single-element array always returns that element.
  • Handles arrays with falsy values (0, '', false, null, undefined) without filtering them out.
  • Does not mutate the input array.
  • Defined behavior on empty arrays (returns undefined or throws a specific error).
  • Works with arrays of objects and mixed types (returns the actual reference).
  • Handles sparse arrays (holes) appropriately.
  • Basic large-array smoke test to ensure consistent behavior.
  • Restores Math.random after each test to prevent cross-test leakage.
git fetch origin
git checkout gitauto/issue-608-20260119-000049-2rtk
git pull origin gitauto/issue-608-20260119-000049-2rtk

@hiroshinishio hiroshinishio merged commit b7aed0b into main Jan 19, 2026
1 check passed
@hiroshinishio hiroshinishio deleted the gitauto/issue-608-20260119-000049-2rtk branch January 19, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schedule: Add unit tests to utils/get-random-item.ts

2 participants