File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -4677,4 +4677,38 @@ describe('useQuery', () => {
4677
4677
4678
4678
consoleMock . mockRestore ( )
4679
4679
} )
4680
+
4681
+ it ( 'it should have status=error on mount when a query has failed' , async ( ) => {
4682
+ const consoleMock = mockConsoleError ( )
4683
+ const key = queryKey ( )
4684
+ const states : UseQueryResult < number > [ ] = [ ]
4685
+ const error = new Error ( 'oops' )
4686
+
4687
+ const queryFn = async ( ) => {
4688
+ throw error
4689
+ }
4690
+
4691
+ function Page ( ) {
4692
+ const state = useQuery ( key , queryFn , {
4693
+ retry : false ,
4694
+ retryOnMount : false ,
4695
+ } )
4696
+
4697
+ states . push ( state )
4698
+
4699
+ return < > </ >
4700
+ }
4701
+
4702
+ await queryClient . prefetchQuery ( key , queryFn )
4703
+ renderWithClient ( queryClient , < Page /> )
4704
+
4705
+ await waitFor ( ( ) => expect ( states ) . toHaveLength ( 1 ) )
4706
+
4707
+ expect ( states [ 0 ] ) . toMatchObject ( {
4708
+ status : 'error' ,
4709
+ error,
4710
+ } )
4711
+
4712
+ consoleMock . mockRestore ( )
4713
+ } )
4680
4714
} )
You can’t perform that action at this time.
0 commit comments