File tree Expand file tree Collapse file tree
preact-query/src/__tests__
solid-query/src/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -855,4 +855,47 @@ describe('useSuspenseQueries 2', () => {
855855 consoleErrorSpy . mockRestore ( )
856856 process . env . NODE_ENV = envCopy
857857 } )
858+
859+ it ( 'should only suspend queries that are pending when some queries already have data' , async ( ) => {
860+ const key1 = queryKey ( )
861+ const key2 = queryKey ( )
862+
863+ queryClient . setQueryData ( key1 , 'cached' )
864+
865+ function Page ( ) {
866+ const [ result1 , result2 ] = useSuspenseQueries ( {
867+ queries : [
868+ {
869+ queryKey : key1 ,
870+ queryFn : ( ) => sleep ( QUERY_DURATION ) . then ( ( ) => 'data1' ) ,
871+ } ,
872+ {
873+ queryKey : key2 ,
874+ queryFn : ( ) => sleep ( QUERY_DURATION ) . then ( ( ) => 'data2' ) ,
875+ } ,
876+ ] ,
877+ } )
878+
879+ return (
880+ < div >
881+ < div > data1: { result1 . data } </ div >
882+ < div > data2: { result2 . data } </ div >
883+ </ div >
884+ )
885+ }
886+
887+ const rendered = renderWithClient (
888+ queryClient ,
889+ < Suspense fallback = { < div > loading</ div > } >
890+ < Page />
891+ </ Suspense > ,
892+ )
893+
894+ expect ( rendered . getByText ( 'loading' ) ) . toBeInTheDocument ( )
895+
896+ await vi . advanceTimersByTimeAsync ( QUERY_DURATION )
897+
898+ expect ( rendered . getByText ( 'data1: cached' ) ) . toBeInTheDocument ( )
899+ expect ( rendered . getByText ( 'data2: data2' ) ) . toBeInTheDocument ( )
900+ } )
858901} )
Original file line number Diff line number Diff line change @@ -18,6 +18,54 @@ describe('useMutationState', () => {
1818 vi . useRealTimers ( )
1919 } )
2020
21+ it ( 'should return all mutation states when called without options' , async ( ) => {
22+ const queryClient = new QueryClient ( )
23+ const mutationKey = [ 'mutation' ]
24+
25+ function States ( ) {
26+ const mutationStates = useMutationState ( )
27+
28+ return < div > count: { mutationStates ( ) . length } </ div >
29+ }
30+
31+ function Mutate ( ) {
32+ const mutation = useMutation ( ( ) => ( {
33+ mutationKey,
34+ mutationFn : ( input : number ) => sleep ( 150 ) . then ( ( ) => 'data' + input ) ,
35+ } ) )
36+
37+ return (
38+ < div >
39+ < button onClick = { ( ) => mutation . mutate ( 1 ) } > mutate</ button >
40+ </ div >
41+ )
42+ }
43+
44+ function Page ( ) {
45+ return (
46+ < div >
47+ < States />
48+ < Mutate />
49+ </ div >
50+ )
51+ }
52+
53+ const rendered = render ( ( ) => (
54+ < QueryClientProvider client = { queryClient } >
55+ < Page />
56+ </ QueryClientProvider >
57+ ) )
58+
59+ expect ( rendered . getByText ( 'count: 0' ) ) . toBeInTheDocument ( )
60+
61+ fireEvent . click ( rendered . getByRole ( 'button' , { name : / m u t a t e / i } ) )
62+ await vi . advanceTimersByTimeAsync ( 0 )
63+ expect ( rendered . getByText ( 'count: 1' ) ) . toBeInTheDocument ( )
64+
65+ await vi . advanceTimersByTimeAsync ( 150 )
66+ expect ( rendered . getByText ( 'count: 1' ) ) . toBeInTheDocument ( )
67+ } )
68+
2169 it ( 'should return variables after calling mutate' , async ( ) => {
2270 const queryClient = new QueryClient ( )
2371 const variables : Array < Array < unknown > > = [ ]
You can’t perform that action at this time.
0 commit comments