Skip to content

Commit 89bae56

Browse files
authored
test(query-persist-client-core/persist): add tests for removing an expired or busted cache in 'persistQueryClientRestore' (TanStack#10876)
1 parent e6c26c0 commit 89bae56

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

packages/query-persist-client-core/src/__tests__/persist.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,39 @@ describe('persist', () => {
177177
expect(persister.removeClient).not.toHaveBeenCalled()
178178
expect(queryClient.getQueryData(['key'])).toBe('data')
179179
})
180+
181+
it('should remove the client when the persisted cache is expired', async () => {
182+
persister.restoreClient = () =>
183+
Promise.resolve({
184+
buster: '',
185+
clientState: { mutations: [], queries: [] },
186+
timestamp: Date.now() - 1000,
187+
})
188+
189+
await persistQueryClientRestore({
190+
queryClient,
191+
persister,
192+
maxAge: 100,
193+
})
194+
195+
expect(persister.removeClient).toHaveBeenCalledTimes(1)
196+
})
197+
198+
it('should remove the client when the buster does not match', async () => {
199+
persister.restoreClient = () =>
200+
Promise.resolve({
201+
buster: 'old-buster',
202+
clientState: { mutations: [], queries: [] },
203+
timestamp: Date.now(),
204+
})
205+
206+
await persistQueryClientRestore({
207+
queryClient,
208+
persister,
209+
buster: 'new-buster',
210+
})
211+
212+
expect(persister.removeClient).toHaveBeenCalledTimes(1)
213+
})
180214
})
181215
})

0 commit comments

Comments
 (0)