@@ -907,6 +907,57 @@ describe('hooks tests', () => {
907
907
}
908
908
} )
909
909
910
+ test ( 'Hook subscription failures do not reset isLoading state' , async ( ) => {
911
+ const states : boolean [ ] = [ ]
912
+
913
+ function Parent ( ) {
914
+ const { isLoading } = api . endpoints . getUserAndForceError . useQuery ( 1 )
915
+
916
+ // Collect loading states to verify that it does not revert back to true.
917
+ states . push ( isLoading )
918
+
919
+ // Parent conditionally renders child when loading.
920
+ if ( isLoading ) return null
921
+
922
+ return < Child />
923
+ }
924
+
925
+ function Child ( ) {
926
+ // Using the same args as the parent
927
+ api . endpoints . getUserAndForceError . useQuery ( 1 )
928
+
929
+ return null
930
+ }
931
+
932
+ render ( < Parent /> , { wrapper : storeRef . wrapper } )
933
+
934
+ // Allow at least three state effects to hit.
935
+ // Trying to see if any [true, false, true] occurs.
936
+ await act ( async ( ) => {
937
+ await waitMs ( 1 )
938
+ } )
939
+
940
+ await act ( async ( ) => {
941
+ await waitMs ( 1 )
942
+ } )
943
+
944
+ await act ( async ( ) => {
945
+ await waitMs ( 1 )
946
+ } )
947
+
948
+ // Find if at any time the isLoading state has reverted
949
+ // E.G.: `[..., true, false, ..., true]`
950
+ // ^^^^ ^^^^^ ^^^^
951
+ const firstTrue = states . indexOf ( true )
952
+ const firstFalse = states . slice ( firstTrue ) . indexOf ( false )
953
+ const revertedState = states . slice ( firstFalse ) . indexOf ( true )
954
+
955
+ expect (
956
+ revertedState ,
957
+ `Expected isLoading state to never revert back to true but did after ${ revertedState } renders...` ,
958
+ ) . toBe ( - 1 )
959
+ } )
960
+
910
961
describe ( 'Hook middleware requirements' , ( ) => {
911
962
let mock : MockInstance
912
963
0 commit comments