Skip to content

fix(utils): make all failing tests pass - #280

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2969-1786291886
Open

fix(utils): make all failing tests pass#280
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2969-1786291886

Conversation

@stooit

@stooit stooit commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across 5 source files in the utility library. Test suite now reports 60 pass, 0 fail. No test files were modified and no dependencies were added.

Changes

  • src/calculator.tsdivide throws on division by zero (including -0) instead of silently returning Infinity/NaN.
  • src/string-utils.ts — implemented truncate (word-boundary truncation with "..." counting toward maxLength; returns unchanged when within limit); fixed wordCount to split on /\s+/ so runs of whitespace no longer inflate the count.
  • src/task-manager.ts — implemented remove (returns true/false), update (returns false for unknown id; partial-update safe via !== undefined checks), and sortBy (priority high>medium>low, status ordering, and createdAt oldest-first).
  • src/date-utils.tsformatRelative off-by-one fixed: round instead of floor so 36 hours reads as "2 days ago"; also corrects the future-dated sign case.
  • src/validator.tsisEmail now accepts long TLDs (e.g. .museum) and multi-level subdomains while still rejecting empty labels; isUrl now accepts URLs with a port (e.g. http://localhost:3000).

Verification

  • bun test → 60 pass, 0 fail
  • bunx tsc --noEmit → clean

Review notes / assumptions

A review flagged two out-of-scope edge cases in truncate that no test covers and that don't affect the documented contract for sane inputs, left as-is per the "fix only what the tests require" constraint:

  • Negative maxLength returns "" (undefined behaviour).
  • A string whose only whitespace is a leading space falls back to a mid-word cut.

isEmail remains a regex approximation (not RFC 5322) — suitable for form-level validation, not as a sole trust gate for delivery/identity.

…e cases

- calculator.divide: throw on division by zero (incl. -0) instead of returning Infinity/NaN
- string-utils.truncate: implement word-boundary truncation with ellipsis counting toward maxLength
- string-utils.wordCount: split on /\s+/ so runs of whitespace no longer inflate the count
- task-manager: implement remove/update (partial-update safe) and sortBy (priority, status, createdAt)
- date-utils.formatRelative: round instead of floor so 36h reads as "2 days ago"; fix future-dated sign
- validator.isEmail: allow long TLDs and multi-level subdomains; isUrl: allow ports

All 60 tests pass. No test files or dependencies changed.
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.

1 participant