-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move React Query setup into main app boilerplate
- Loading branch information
Stephen Hanson
committed
May 3, 2024
1 parent
fc7a332
commit 271cb7d
Showing
15 changed files
with
81 additions
and
31 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
This file was deleted.
Oops, something went wrong.
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
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
File renamed without changes.
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 |
---|---|---|
@@ -1,15 +1,44 @@ | ||
import { NavigationContainer } from '@react-navigation/native'; | ||
import { QueryClientProvider } from '@tanstack/react-query'; | ||
import { | ||
RenderAPI, | ||
// eslint-disable-next-line no-restricted-imports | ||
render as TestingLibraryRender, | ||
} from '@testing-library/react-native'; | ||
import { RequestHandler } from 'msw'; | ||
import { ReactElement } from 'react'; | ||
import Providers, { Provider } from 'src/components/Providers'; | ||
import RootNavigator from 'src/navigators/RootNavigator'; | ||
import queryClient from 'src/util/api/queryClient'; | ||
import server from './server'; | ||
|
||
export type RenderOptions = { | ||
mocks?: Array<RequestHandler>; | ||
}; | ||
|
||
// TODO: this will become customized as the codebase progresses, so our | ||
// tests can be wrapped with appropriate providers, mocks can be supplied, etc | ||
export default function render(element: ReactElement): RenderAPI { | ||
export default function render( | ||
element: ReactElement, | ||
{ mocks }: RenderOptions = {}, | ||
): RenderAPI { | ||
if (mocks) { | ||
server.use(...mocks); | ||
} | ||
|
||
const providers: Provider[] = [ | ||
(children) => ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
), | ||
(children) => <NavigationContainer>{children}</NavigationContainer>, | ||
// CODEGEN:BELT:PROVIDERS - do not remove | ||
]; | ||
|
||
return TestingLibraryRender( | ||
<NavigationContainer>{element}</NavigationContainer>, | ||
<Providers providers={providers}>{element}</Providers>, | ||
); | ||
} | ||
|
||
export function renderApplication(options: RenderOptions = {}) { | ||
return render(<RootNavigator />, options); | ||
} |
File renamed without changes.
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,5 @@ | ||
export default function sleep(ms: number) { | ||
return new Promise<void>((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
} |
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,12 @@ | ||
import { act } from '@testing-library/react-native'; | ||
import sleep from './sleep'; | ||
|
||
/** | ||
* Wait a specified time, wrapped in act | ||
* Usually, it is better to use waitFor or a findBy* matcher, | ||
* but this is sometimes required | ||
* @param time | ||
*/ | ||
export default async function waitForUpdates(time = 2) { | ||
return act(() => sleep(time)); | ||
} |
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
File renamed without changes.
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