test : added unit tests for useCountUp hook#785
Conversation
|
@TESTPERSONAL is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
Tests must import from source — not reimplement the function locally.
The test file re-implements the function being tested inside the test itself. This defeats the purpose of testing — changes to the real implementation won't fail these tests.
Fix: import the actual function from its source file and test that import. Example:
import { safeCompare } from '../src/lib/crypto'
// then test safeCompare directlyAlso fix:
- Add
"test": "vitest run"toscriptsinpackage.json - Add
vitest.config.tswithresolve.alias: { '@': path.resolve(__dirname, 'src') } - Add EOF newline to test file
2ed957a to
78b0378
Compare
|
Deployment failed with the following error: |
Closes Priyanshu-byte-coder#765 Added test/useCountUp.test.ts covering the useCountUp hook's pure logic and animation behavior: - Adaptive duration: small (<=10) → 500ms, medium (<=50) → 650ms, large → 800ms - Quintic ease-out formula never exceeds target - Progress capped at 1 for elapsed > duration - Negative target guard: returns 0 - Target of zero returns zero immediately - All intermediate counts are within valid range Uses vi.useFakeTimers() and vi.useRealTimers() for time-dependent tests. Impact: useCountUp hook's animation logic is now validated.
…test for type checking
|
This pull request is fully up-to-date with the latest upstream merges, all review items are addressed, local tests are passing cleanly, and it is fully ready to be merged! 🚀 |
Closes #765.
Summary of What Has Been Done:
Added test/useCountUp.test.ts covering the useCountUp hook's pure logic and animation behavior.
Changes Made:
New file: test/useCountUp.test.ts
Test coverage (9 tests):
Uses vi.useFakeTimers() for deterministic time testing.
Impact it Made:
All 9 tests pass. The animated counter logic is validated across edge cases without requiring a full React render test setup.