Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

useQueries.test.tsx

45 lines1.1 KB

1import React from 'react'
2​
3import { queryKey, renderWithClient, sleep } from './utils'
4import { useQueries, QueryClient, UseQueryResult, QueryCache } from '../..'
5​
6describe('useQueries', () => {
7 const queryCache = new QueryCache()
8 const queryClient = new QueryClient({ queryCache })
9​
10 it('should return the correct states', async () => {
11 const key1 = queryKey()
12 const key2 = queryKey()
13 const results: UseQueryResult[][] = []
14​
15 function Page() {
16 const result = useQueries([
17 {
18 queryKey: key1,
19 queryFn: async () => {
20 await sleep(5)
21 return 1
22 },
23 },
24 {
25 queryKey: key2,
26 queryFn: async () => {
27 await sleep(10)
28 return 2
29 },
30 },
31 ])
32 results.push(result)
33 return null
34 }
35​
36 renderWithClient(queryClient, <Page />)
37​
38 await sleep(30)
39​
40 expect(results.length).toBe(3)
41 expect(results[0]).toMatchObject([{ data: undefined }, { data: undefined }])
42 expect(results[1]).toMatchObject([{ data: 1 }, { data: undefined }])
43 expect(results[2]).toMatchObject([{ data: 1 }, { data: 2 }])
44 })
45})