Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 10 additions & 36 deletions packages/react-query/src/__tests__/useIsFetching.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ describe('useIsFetching', () => {

useQuery({
queryKey: key,
queryFn: async () => {
await sleep(50)
return 'test'
},
queryFn: () => sleep(50).then(() => 'test'),
enabled: ready,
})

Expand All @@ -54,10 +51,8 @@ describe('useIsFetching', () => {
expect(getByText('isFetching: 0')).toBeInTheDocument()

fireEvent.click(getByRole('button', { name: /setReady/i }))

await vi.advanceTimersByTimeAsync(0)
expect(getByText('isFetching: 1')).toBeInTheDocument()

await vi.advanceTimersByTimeAsync(51)
expect(getByText('isFetching: 0')).toBeInTheDocument()
})
Expand All @@ -80,21 +75,15 @@ describe('useIsFetching', () => {
function FirstQuery() {
useQuery({
queryKey: key1,
queryFn: async () => {
await sleep(100)
return 'data'
},
queryFn: () => sleep(100).then(() => 'data'),
})
return null
}

function SecondQuery() {
useQuery({
queryKey: key2,
queryFn: async () => {
await sleep(100)
return 'data'
},
queryFn: () => sleep(100).then(() => 'data'),
})
return null
}
Expand Down Expand Up @@ -133,21 +122,15 @@ describe('useIsFetching', () => {
function One() {
useQuery({
queryKey: key1,
queryFn: async () => {
await sleep(10)
return 'test'
},
queryFn: () => sleep(10).then(() => 'test'),
})
return null
}

function Two() {
useQuery({
queryKey: key2,
queryFn: async () => {
await sleep(20)
return 'test'
},
queryFn: () => sleep(20).then(() => 'test'),
})
return null
}
Expand All @@ -174,15 +157,13 @@ describe('useIsFetching', () => {

const { getByText, getByRole } = renderWithClient(queryClient, <Page />)

getByText('isFetching: 0')
expect(getByText('isFetching: 0')).toBeInTheDocument()

fireEvent.click(getByRole('button', { name: /setStarted/i }))

await vi.advanceTimersByTimeAsync(0)
getByText('isFetching: 1')

expect(getByText('isFetching: 1')).toBeInTheDocument()
await vi.advanceTimersByTimeAsync(11)
getByText('isFetching: 0')
expect(getByText('isFetching: 0')).toBeInTheDocument()

// at no point should we have isFetching: 2
expect(isFetchingArray).toEqual(expect.not.arrayContaining([2]))
Expand All @@ -195,10 +176,7 @@ describe('useIsFetching', () => {
function Page() {
useQuery({
queryKey: key,
queryFn: async () => {
await sleep(10)
return 'test'
},
queryFn: () => sleep(10).then(() => 'test'),
})

const isFetching = useIsFetching()
Expand All @@ -214,7 +192,6 @@ describe('useIsFetching', () => {

await vi.advanceTimersByTimeAsync(0)
expect(rendered.getByText('isFetching: 1')).toBeInTheDocument()

await vi.advanceTimersByTimeAsync(11)
expect(rendered.getByText('isFetching: 0')).toBeInTheDocument()
})
Expand All @@ -227,10 +204,7 @@ describe('useIsFetching', () => {
useQuery(
{
queryKey: key,
queryFn: async () => {
await sleep(10)
return 'test'
},
queryFn: () => sleep(10).then(() => 'test'),
},
queryClient,
)
Expand Down
Loading