Skip to content

Commit

Permalink
Fix query client instance & unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mlqn committed Aug 23, 2023
1 parent 8401520 commit 2ba1675
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 9 additions & 10 deletions frontend/packages/shared/src/contexts/ServicesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ export const ServicesContextProvider = ({
const { t } = useTranslation();

const [queryClient] = useState(
() =>
new QueryClient({
queryCache: new QueryCache({
onError: (error: AxiosError, query) => handleError(error, t, query.options?.meta),
}),
mutationCache: new MutationCache({
onError: (error: AxiosError, variables, context, mutation) => handleError(error, t, mutation.options?.meta),
}),
})
() => client || new QueryClient({
queryCache: new QueryCache({
onError: (error: AxiosError, query) => handleError(error, t, query.options?.meta),

Check warning on line 61 in frontend/packages/shared/src/contexts/ServicesContext.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/packages/shared/src/contexts/ServicesContext.tsx#L61

Added line #L61 was not covered by tests
}),
mutationCache: new MutationCache({
onError: (error: AxiosError, variables, context, mutation) => handleError(error, t, mutation.options?.meta),
}),
})
);

return (
Expand All @@ -80,7 +79,7 @@ export const ServicesContextProvider = ({
theme='colored'
transition={Slide}
/>
<QueryClientProvider client={client || queryClient}>
<QueryClientProvider client={queryClient}>
<ServicesContext.Provider value={{ ...queries }}>{children}</ServicesContext.Provider>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ describe('TextResourceEdit', () => {
});

it('Does not render anything if edit id is undefined', async () => {
const { renderResult } = await render();
expect(renderResult.container).toBeEmptyDOMElement();
await render();
expect(screen.queryByText(legendText)).not.toBeInTheDocument();
expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: closeText })).not.toBeInTheDocument();
});

it('Renders correctly when a valid edit id is given', async () => {
Expand Down

0 comments on commit 2ba1675

Please sign in to comment.