Skip to content

fix: resolve failing tests across utility library - #321

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2203-1788625024
Open

fix: resolve failing tests across utility library#321
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2203-1788625024

Conversation

@stooit

@stooit stooit commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 previously-failing tests across the utility library. The suite now reports 60 pass / 0 fail, with npx tsc --noEmit clean. No test files were modified and no dependencies were added.

Changes by file

  • src/calculator.tsdivide throws Error("Division by zero") when the divisor is 0 instead of silently returning Infinity.
  • src/string-utils.ts
    • wordCount — trims then splits on /\s+/ so runs of whitespace no longer inflate the count ("hello world" → 2). Also handles tabs/newlines.
    • truncate — implemented: returns the string unchanged when str.length <= maxLength; otherwise truncates at a word boundary, reserving 3 chars for "..." so the ellipsis counts toward maxLength. Falls back to a hard slice when maxLength <= 3 so the result never exceeds maxLength.
  • src/date-utils.tsdiffDays uses Math.round(Math.abs(hours)/24) to fix the off-by-one (36h now → "2 days ago"), and corrects a latent bug on the future-date branch.
  • src/task-manager.ts — implemented/completed remove (returns whether a task existed), update (applies only supplied keys, returns false for a missing id), and sortBy (priority, status, and createdAt ordering).
  • src/validator.ts
    • isEmail — supports multi-level subdomains and longer TLDs, and rejects empty/consecutive-dot labels.
    • isUrl — accepts URLs with explicit ports (e.g. http://localhost:3000) while still allowlisting http/https.

Testing

  • bun test → 60 pass, 0 fail
  • npx tsc --noEmit → exit 0

Assumptions

  • The tests are the authoritative spec; changes were kept minimal to satisfy them without altering unrelated behaviour.
  • truncate guarantees its return value never exceeds maxLength, hard-slicing when there is no room for a word plus ellipsis.
  • update treats an omitted field as "leave unchanged" and only allows explicitly clearing the optional description.

Note

isEmail is a syntactic check only — if used to gate account creation, pair it with a confirmation-link verification step.

…on utils

- calculator.divide: throw on division by zero instead of returning Infinity
- string-utils.wordCount: split on whitespace runs so consecutive spaces don't inflate count
- string-utils.truncate: implement word-boundary truncation with ellipsis counting toward maxLength
- date-utils.diffDays: fix off-by-one by rounding hours/24 (and correct future-date branch)
- task-manager: implement/complete remove, update, and sortBy
- validator.isEmail: support multi-level subdomains and longer TLDs, reject empty labels
- validator.isUrl: accept URLs with explicit ports (e.g. localhost:3000)
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