Skip to content

fix: resolve all failing tests in utility library#224

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2295-1782234030
Open

fix: resolve all failing tests in utility library#224
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2295-1782234030

Conversation

@stooit

@stooit stooit commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across 5 source files in the TypeScript utility library. All 60 tests now pass (previously 44 pass / 16 fail). No test files were modified and no dependencies were added.

Changes by file

  • src/calculator.tsdivide now throws "Division by zero" instead of silently returning Infinity.
  • src/date-utils.ts — fixed off-by-one in formatRelative: uses Math.round for day calculation so 36 hours ago correctly renders as "2 days ago".
  • src/string-utils.ts — implemented truncate (word-boundary truncation, ellipsis counting toward maxLength, handling strings shorter than the ellipsis, and returning unchanged when within limit); fixed wordCount to collapse multiple consecutive spaces.
  • src/task-manager.ts — implemented missing remove, update, and sortBy (priority and createdAt ordering) methods.
  • src/validator.ts — fixed isEmail to accept long TLDs and subdomains; rewrote isUrl using the URL constructor so URLs with ports (e.g. http://localhost:3000) validate correctly.

Verification

  • bun test60 pass, 0 fail
  • Independent code review confirmed all fixes are correct implementations of intended behaviour, not special-casing of test inputs.

Assumptions

  • The intended divide behaviour on zero is to throw (consistent with the test expecting an error).
  • formatRelative uses round-half semantics for the hours/days boundary, consistent with the 36h → "2 days ago" test.
  • Email/URL validators favour the permissive-but-standard approach used in utility libraries.

- calculator: divide now throws on division by zero
- date-utils: fix off-by-one in formatRelative (round vs floor)
- string-utils: implement truncate word-boundary/ellipsis logic and fix wordCount
- task-manager: implement remove, update, and sortBy methods
- validator: fix isEmail long-TLD/subdomain and isUrl port handling
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