From 968ec3a7d2255444f8a38b1f84e92c67a8ef0bd8 Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 10 Aug 2022 10:30:58 -0400 Subject: [PATCH] Clear React Query cache before each test --- app/soapbox/jest/test-helpers.tsx | 3 +++ app/soapbox/jest/test-setup.ts | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/soapbox/jest/test-helpers.tsx b/app/soapbox/jest/test-helpers.tsx index 0894d4d40..721783879 100644 --- a/app/soapbox/jest/test-helpers.tsx +++ b/app/soapbox/jest/test-helpers.tsx @@ -37,6 +37,8 @@ const queryClient = new QueryClient({ }, defaultOptions: { queries: { + staleTime: 0, + cacheTime: Infinity, retry: false, }, }, @@ -123,4 +125,5 @@ export { rootReducer, mockWindowProperty, createTestStore, + queryClient, }; diff --git a/app/soapbox/jest/test-setup.ts b/app/soapbox/jest/test-setup.ts index 0052388b0..cf24ba3f1 100644 --- a/app/soapbox/jest/test-setup.ts +++ b/app/soapbox/jest/test-setup.ts @@ -2,9 +2,14 @@ import { __clear as clearApiMocks } from '../__mocks__/api'; +import { queryClient } from './test-helpers'; + // API mocking jest.mock('soapbox/api'); -afterEach(() => clearApiMocks()); +afterEach(() => { + clearApiMocks(); + queryClient.clear(); +}); // Mock IndexedDB // https://dev.to/andyhaskell/testing-your-indexeddb-code-with-jest-2o17