From e96669dca8b129336aaffbcf7ee15505b432cbe9 Mon Sep 17 00:00:00 2001 From: Jaga Santagostino Date: Sat, 25 Mar 2023 15:56:26 +0100 Subject: [PATCH] feat(react-query-devtools): add button to clear cache --- .../src/__tests__/devtools.test.tsx | 37 +++++++++++++++++++ .../react-query-devtools/src/devtools.tsx | 15 ++++++++ 2 files changed, 52 insertions(+) diff --git a/packages/react-query-devtools/src/__tests__/devtools.test.tsx b/packages/react-query-devtools/src/__tests__/devtools.test.tsx index b0de85d4b6..aab520d058 100644 --- a/packages/react-query-devtools/src/__tests__/devtools.test.tsx +++ b/packages/react-query-devtools/src/__tests__/devtools.test.tsx @@ -661,6 +661,43 @@ describe('ReactQueryDevtools', () => { expect(filterInput.value).toEqual('posts') }) + it('should not show queries after clear', async () => { + const { queryClient, queryCache } = createQueryClient() + + function Page() { + const query1Result = useQuery(['query-1'], async () => { + return 'query-1-result' + }) + const query2Result = useQuery(['query-2'], async () => { + return 'query-2-result' + }) + const query3Result = useQuery(['query-3'], async () => { + return 'query-3-result' + }) + + return ( +
+

+ {query1Result.data} {query2Result.data} {query3Result.data}{' '} +

+
+ ) + } + + renderWithClient(queryClient, ) + + fireEvent.click( + screen.getByRole('button', { name: /open react query devtools/i }), + ) + + expect(queryCache.getAll()).toHaveLength(3) + + const clearButton = screen.getByLabelText(/clear/i) + fireEvent.click(clearButton) + + expect(queryCache.getAll()).toHaveLength(0) + }) + it('style should have a nonce', async () => { const { queryClient } = createQueryClient() diff --git a/packages/react-query-devtools/src/devtools.tsx b/packages/react-query-devtools/src/devtools.tsx index 66cad7c4d9..edc1b817fe 100644 --- a/packages/react-query-devtools/src/devtools.tsx +++ b/packages/react-query-devtools/src/devtools.tsx @@ -597,6 +597,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef< +
{baseSort === 1 ? '⬆ Asc' : '⬇ Desc'} +