[MOB-12160] add unit tests for useDeviceOrientation#708
Conversation
|
Diff Coverage: Not applicable. There was no coverage data reported for the files in this diff. Total Coverage: This PR will increase coverage by 1.07%. File Coverage Changes
🛟 Help
This is from Qlty Cloud, the successor to Code Climate Quality. Learn more. |
…to feature/MOB-12160-add-tests-for-usedeviceorientation
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive unit tests for the useDeviceOrientation hook to improve test coverage and ensure the hook behaves correctly across various scenarios.
Key changes:
- Added 424 lines of unit tests covering initial state, orientation changes, edge cases, hook behavior, and type safety
- Tests verify portrait/landscape detection logic based on height vs width comparison
- Includes edge case testing for zero, negative, and decimal dimensions
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| }); | ||
|
|
||
| act(() => { | ||
| rerender(() => useDeviceOrientation()); |
There was a problem hiding this comment.
The rerender callback should not recreate the hook function on each call. Pass the existing hook result or use rerender({}) to trigger a re-render without recreating the hook.
| rerender(() => useDeviceOrientation()); | |
| rerender(); |
| }); | ||
|
|
||
| act(() => { | ||
| rerender(() => useDeviceOrientation()); |
There was a problem hiding this comment.
The rerender callback should not recreate the hook function on each call. Pass the existing hook result or use rerender({}) to trigger a re-render without recreating the hook.
| }); | ||
|
|
||
| act(() => { | ||
| rerender(() => useDeviceOrientation()); |
There was a problem hiding this comment.
The rerender callback should not recreate the hook function on each call. Pass the existing hook result or use rerender({}) to trigger a re-render without recreating the hook.
| }); | ||
|
|
||
| act(() => { | ||
| rerender(() => useDeviceOrientation()); |
There was a problem hiding this comment.
The rerender callback should not recreate the hook function on each call. Pass the existing hook result or use rerender({}) to trigger a re-render without recreating the hook.
|
|
||
| // WHEN component re-renders with same dimensions | ||
| act(() => { | ||
| rerender(() => useDeviceOrientation()); |
There was a problem hiding this comment.
The rerender callback should not recreate the hook function on each call. Pass the existing hook result or use rerender({}) to trigger a re-render without recreating the hook.
| }); | ||
|
|
||
| act(() => { | ||
| rerender(() => useDeviceOrientation()); |
There was a problem hiding this comment.
The rerender callback should not recreate the hook function on each call. Pass the existing hook result or use rerender({}) to trigger a re-render without recreating the hook.
| }); | ||
|
|
||
| act(() => { | ||
| rerender(() => useDeviceOrientation()); |
There was a problem hiding this comment.
The rerender callback should not recreate the hook function on each call. Pass the existing hook result or use rerender({}) to trigger a re-render without recreating the hook.
Ayyanchira
left a comment
There was a problem hiding this comment.
Not quite sure I understand the Why behind this to its extent, but looks like orientation testing with intention of whether the hooks are getting called correctly adn veriyfing the dimensions is the approach here.
Looks good to me. Just never saw the negative dimensions before 😅. But could be the case for RN
🔹 JIRA Ticket(s) if any
✏️ Description
add unit tests for useDeviceOrientation