-
Notifications
You must be signed in to change notification settings - Fork 1
YPE-1159 - useChapter and useChapters tests #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Kyleasmth
commented
Feb 3, 2026
|
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Greptile OverviewGreptile SummaryAdded comprehensive test suites for Key changes:
Minor gaps:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Test as Test Suite
participant Hook as useChapter/useChapters
participant Client as BibleClient (mocked)
participant API as useApiData
Test->>Hook: renderHook(versionId, book, chapter?)
Hook->>Client: useBibleClient()
Client-->>Hook: mockClient
Hook->>API: useApiData(fetchFn, deps, options)
API-->>Hook: {data, loading: true, error, refetch}
Hook-->>Test: {chapter/chapters: null, loading: true}
Note over API: useEffect triggered
API->>Client: getChapter(versionId, book, chapter)
Client-->>API: Promise<BibleChapter>
API-->>Hook: {data: chapter, loading: false}
Hook-->>Test: {chapter: mockChapter, loading: false}
Test->>Hook: rerender with new params
Note over API: Dependencies changed
API->>Client: getChapter(newVersionId, book, chapter)
Client-->>API: Promise<BibleChapter>
Hook-->>Test: Updated chapter data
Test->>Hook: result.current.refetch()
Hook->>API: refetch()
API->>Client: getChapter(versionId, book, chapter)
Client-->>API: Promise<BibleChapter>
Hook-->>Test: Refetched chapter data
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 2 comments
| it('should handle fetch errors', async () => { | ||
| const error = new Error('Failed to fetch chapter'); | ||
| mockGetChapter.mockRejectedValueOnce(error); | ||
|
|
||
| const wrapper = createWrapper({ | ||
| appKey: mockAppKey, | ||
| }); | ||
|
|
||
| const { result } = renderHook(() => useChapter(1, 'MAT', 1), { wrapper }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current.loading).toBe(false); | ||
| }); | ||
|
|
||
| expect(result.current.error).toEqual(error); | ||
| expect(result.current.chapter).toBe(null); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test for error recovery. useVersion.test.tsx:188 and useVersions.test.tsx:587 include tests verifying that errors are cleared after a successful refetch using mockRejectedValueOnce(error).mockResolvedValueOnce(data) pattern
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hooks/src/useChapter.test.tsx
Line: 159:175
Comment:
Missing test for error recovery. `useVersion.test.tsx:188` and `useVersions.test.tsx:587` include tests verifying that errors are cleared after a successful refetch using `mockRejectedValueOnce(error).mockResolvedValueOnce(data)` pattern
How can I resolve this? If you propose a fix, please make it concise.| it('should handle fetch errors', async () => { | ||
| const error = new Error('Failed to fetch chapters'); | ||
| mockGetChapters.mockRejectedValueOnce(error); | ||
|
|
||
| const wrapper = createWrapper({ | ||
| appKey: mockAppKey, | ||
| }); | ||
|
|
||
| const { result } = renderHook(() => useChapters(1, 'MAT'), { wrapper }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current.loading).toBe(false); | ||
| }); | ||
|
|
||
| expect(result.current.error).toEqual(error); | ||
| expect(result.current.chapters).toBe(null); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test for error recovery. useVersion.test.tsx:188 and useVersions.test.tsx:587 include tests verifying that errors are cleared after a successful refetch using mockRejectedValueOnce(error).mockResolvedValueOnce(data) pattern
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hooks/src/useChapters.test.tsx
Line: 133:149
Comment:
Missing test for error recovery. `useVersion.test.tsx:188` and `useVersions.test.tsx:587` include tests verifying that errors are cleared after a successful refetch using `mockRejectedValueOnce(error).mockResolvedValueOnce(data)` pattern
How can I resolve this? If you propose a fix, please make it concise.