Skip to content

Commit 0249bbd

Browse files
authored
test(vue-query/useQueries): add test for 'refetch' of individual query without affecting others (#10242)
1 parent 3761d2b commit 0249bbd

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

packages/vue-query/src/__tests__/useQueries.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,35 @@ describe('useQueries', () => {
369369
expect(fetchFn).toHaveBeenCalledTimes(6)
370370
})
371371

372+
test('should refetch only the specific query without affecting others', async () => {
373+
let userCount = 0
374+
let postCount = 0
375+
376+
const queriesState = useQueries({
377+
queries: [
378+
{
379+
queryKey: ['users'],
380+
queryFn: () => sleep(10).then(() => `users-${++userCount}`),
381+
},
382+
{
383+
queryKey: ['posts'],
384+
queryFn: () => sleep(20).then(() => `posts-${++postCount}`),
385+
},
386+
],
387+
})
388+
389+
await vi.advanceTimersByTimeAsync(20)
390+
391+
expect(queriesState.value[0].data).toBe('users-1')
392+
expect(queriesState.value[1].data).toBe('posts-1')
393+
394+
queriesState.value[0].refetch()
395+
await vi.advanceTimersByTimeAsync(10)
396+
397+
expect(queriesState.value[0].data).toBe('users-2')
398+
expect(queriesState.value[1].data).toBe('posts-1')
399+
})
400+
372401
test('should warn when used outside of setup function in development mode', () => {
373402
vi.stubEnv('NODE_ENV', 'development')
374403
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})

0 commit comments

Comments
 (0)