react-queryのtest
https://tkdodo.eu/blog/testing-react-query
MSWを使う
テストごとにQueryClientProviderを用意する
テストごとにキャッシュの空間が分離される
並列にテストを実行しても大丈夫
react-hooks-testing-libraryでcustom hooksのテストをする
React Testing LibraryでComponentのテストをする
こういうrappwrをかます
code:ts
const queryClient = new QueryClient();
const Wrapper: React.FC<{ children: ReactNode }> = props => (
<QueryClientProvider client={queryClient}>
{props.children}
</QueryClientProvider>
);
retryする設定をoffにしておく
setQueryDefaultsを使ってqueryをセットしておくこともできる(あまりやらない)
テストするComponentの子がuseQueryを使っている場合もどうにかなる
ReactQueryConfigProviderを作って使う
https://github.com/TkDodo/testing-react-query も参考にすると良い
https://react-query.tanstack.com/guides/testing
https://oita.oika.me/2021/09/19/react-query-stub