File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ import { render , waitForElement , cleanup } from '@testing-library/react'
2+ import * as React from 'react'
3+
4+ import { useQuery , queryCache } from '../index'
5+ import { sleep } from './utils'
6+
7+ describe ( "useQuery's in Suspense mode" , ( ) => {
8+ afterEach ( ( ) => {
9+ queryCache . clear ( )
10+ cleanup ( )
11+ } )
12+
13+ it ( 'should not call the queryFn twice when used in Suspense mode' , async ( ) => {
14+ const queryFn = jest . fn ( )
15+ queryFn . mockImplementation ( ( ) => sleep ( 10 ) )
16+
17+ function Page ( ) {
18+ useQuery ( [ 'test' ] , queryFn , { suspense : true } )
19+
20+ return 'rendered'
21+ }
22+
23+ const rendered = render (
24+ < React . Suspense fallback = "loading" >
25+ < Page />
26+ </ React . Suspense >
27+ )
28+
29+ await waitForElement ( ( ) => rendered . getByText ( 'rendered' ) )
30+
31+ expect ( queryFn ) . toHaveBeenCalledTimes ( 1 )
32+ } )
33+ } )
You can’t perform that action at this time.
0 commit comments