test: Add comprehensive tests for 5 previously untested hooks#1882
Closed
imbhargav5 wants to merge 2 commits intomainfrom
Closed
test: Add comprehensive tests for 5 previously untested hooks#1882imbhargav5 wants to merge 2 commits intomainfrom
imbhargav5 wants to merge 2 commits intomainfrom
Conversation
Add comprehensive test coverage for hooks that were missing tests: - useBoundingclientrect: 12 tests covering basic functionality, DOMRect properties, mutation tracking, edge cases, cleanup, multiple instances, SSR compatibility, performance, and different element types - useGlobalObjectEventListener: 24 tests covering window/document listeners, event handling, cleanup, listener options (capture, once, passive), conditional attachment, layout effect option, fresh callbacks, edge cases, multiple instances, and real-world scenarios - useMergeRefs: 25 tests covering mutable refs, callback refs, mixed refs, null/undefined handling, memoization, React component integration, edge cases, TypeScript type safety, and performance - useRefElement: 27 tests covering basic functionality, ref callbacks, callback stability, React integration, different element types, state updates, multiple instances, edge cases, cleanup, and real-world use cases - useResizeObserverRef: Enhanced from 2 to 27 tests, adding coverage for callback execution, fresh callbacks, cleanup, options (box types), ref stability, multiple elements, element switching, edge cases, and performance Total: 115 new tests added (126 passing, 1 skipped) All tests follow the established patterns in the repository: - Use @testing-library/react-hooks for hook testing - Include expect.hasAssertions() at the start of each test - Test memoization/function reference stability - Verify cleanup on unmount - Test SSR compatibility where applicable - Cover edge cases, error handling, and performance scenarios
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
✅ Deploy Preview for rooksjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Fix TypeScript compilation errors in hook tests: - useGlobalObjectEventListener.spec.tsx: Add all 6 required parameters (globalObject, eventName, callback, listenerOptions, when, isLayoutEffect) to all function calls to satisfy the function overload signatures - useMergeRefs.spec.tsx: Fix callback ref return types - callbacks must return void or cleanup function, not numbers. Changed arrow functions from implicit return of array.push() to explicit void return All tests still pass (126 passing, 1 skipped) Typecheck now passes successfully
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add comprehensive test coverage for hooks that were missing tests:
useBoundingclientrect: 12 tests covering basic functionality, DOMRect
properties, mutation tracking, edge cases, cleanup, multiple instances,
SSR compatibility, performance, and different element types
useGlobalObjectEventListener: 24 tests covering window/document listeners,
event handling, cleanup, listener options (capture, once, passive),
conditional attachment, layout effect option, fresh callbacks, edge cases,
multiple instances, and real-world scenarios
useMergeRefs: 25 tests covering mutable refs, callback refs, mixed refs,
null/undefined handling, memoization, React component integration, edge
cases, TypeScript type safety, and performance
useRefElement: 27 tests covering basic functionality, ref callbacks,
callback stability, React integration, different element types, state
updates, multiple instances, edge cases, cleanup, and real-world use cases
useResizeObserverRef: Enhanced from 2 to 27 tests, adding coverage for
callback execution, fresh callbacks, cleanup, options (box types), ref
stability, multiple elements, element switching, edge cases, and performance
Total: 115 new tests added (126 passing, 1 skipped)
All tests follow the established patterns in the repository: