-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract query provider, write test for useResumeData
- Loading branch information
1 parent
1858c5a
commit fb475fd
Showing
3 changed files
with
46 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PropsWithChildren } from 'react'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
|
||
export const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
staleTime: 60 * 60 * 1000, | ||
refetchOnWindowFocus: false, | ||
retry: 2, | ||
}, | ||
}, | ||
}); | ||
|
||
export function QueryProvider({ children }: PropsWithChildren) { | ||
return ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
); | ||
} | ||
|
||
export function withClient(client: QueryClient) { | ||
return function QueryProviderWithClient({ children }: PropsWithChildren) { | ||
return ( | ||
<QueryClientProvider client={client}>{children}</QueryClientProvider> | ||
); | ||
}; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { QueryClient } from '@tanstack/react-query'; | ||
import { renderHook, waitFor } from '@testing-library/react'; | ||
import useResumeData from 'hooks/useResumeData'; | ||
import { withClient } from 'contexts/query'; | ||
|
||
describe('useResumeData', async () => { | ||
test('should render the hook correctly', async () => { | ||
const queryClient = new QueryClient(); | ||
const { result } = renderHook(useResumeData, { | ||
wrapper: withClient(queryClient), | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(result.current.data).toBeDefined(); | ||
}); | ||
}); | ||
}); |