@@ -3612,136 +3612,6 @@ describe("useQuery Hook", () => {
3612
3612
await expect ( takeSnapshot ) . not . toRerender ( ) ;
3613
3613
} ) ;
3614
3614
3615
- it ( 'calls `onCompleted` with partial data but avoids calling `onError` when using an `errorPolicy` set to "ignore"' , async ( ) => {
3616
- const query = gql `
3617
- {
3618
- hello
3619
- }
3620
- ` ;
3621
- const mocks = [
3622
- {
3623
- request : { query } ,
3624
- result : {
3625
- data : { hello : null } ,
3626
- errors : [ new GraphQLError ( 'Could not fetch "hello"' ) ] ,
3627
- } ,
3628
- } ,
3629
- ] ;
3630
-
3631
- const cache = new InMemoryCache ( ) ;
3632
- const wrapper = ( { children } : any ) => (
3633
- < MockedProvider mocks = { mocks } cache = { cache } >
3634
- { children }
3635
- </ MockedProvider >
3636
- ) ;
3637
-
3638
- const onError = jest . fn ( ) ;
3639
- const onCompleted = jest . fn ( ) ;
3640
- using _disabledAct = disableActEnvironment ( ) ;
3641
- const { takeSnapshot } = await renderHookToSnapshotStream (
3642
- ( ) => useQuery ( query , { onError, onCompleted, errorPolicy : "ignore" } ) ,
3643
- { wrapper }
3644
- ) ;
3645
-
3646
- {
3647
- const result = await takeSnapshot ( ) ;
3648
-
3649
- expect ( result ) . toEqualQueryResult ( {
3650
- data : undefined ,
3651
- called : true ,
3652
- loading : true ,
3653
- networkStatus : NetworkStatus . loading ,
3654
- previousData : undefined ,
3655
- variables : { } ,
3656
- } ) ;
3657
- }
3658
-
3659
- {
3660
- const result = await takeSnapshot ( ) ;
3661
-
3662
- expect ( result ) . toEqualQueryResult ( {
3663
- data : { hello : null } ,
3664
- called : true ,
3665
- loading : false ,
3666
- networkStatus : NetworkStatus . ready ,
3667
- previousData : undefined ,
3668
- variables : { } ,
3669
- } ) ;
3670
- }
3671
-
3672
- expect ( onCompleted ) . toHaveBeenCalledTimes ( 1 ) ;
3673
- expect ( onCompleted ) . toHaveBeenCalledWith ( { hello : null } ) ;
3674
- expect ( onError ) . not . toHaveBeenCalled ( ) ;
3675
-
3676
- await expect ( takeSnapshot ) . not . toRerender ( ) ;
3677
- } ) ;
3678
-
3679
- it ( 'calls `onError` when returning GraphQL errors while using an `errorPolicy` set to "all"' , async ( ) => {
3680
- const query = gql `
3681
- {
3682
- hello
3683
- }
3684
- ` ;
3685
- const mocks = [
3686
- {
3687
- request : { query } ,
3688
- result : {
3689
- errors : [ new GraphQLError ( "error" ) ] ,
3690
- } ,
3691
- } ,
3692
- ] ;
3693
-
3694
- const cache = new InMemoryCache ( ) ;
3695
- const wrapper = ( { children } : any ) => (
3696
- < MockedProvider mocks = { mocks } cache = { cache } >
3697
- { children }
3698
- </ MockedProvider >
3699
- ) ;
3700
-
3701
- const onError = jest . fn ( ) ;
3702
- using _disabledAct = disableActEnvironment ( ) ;
3703
- const { takeSnapshot } = await renderHookToSnapshotStream (
3704
- ( ) => useQuery ( query , { onError, errorPolicy : "all" } ) ,
3705
- { wrapper }
3706
- ) ;
3707
-
3708
- {
3709
- const result = await takeSnapshot ( ) ;
3710
-
3711
- expect ( result ) . toEqualQueryResult ( {
3712
- data : undefined ,
3713
- called : true ,
3714
- loading : true ,
3715
- networkStatus : NetworkStatus . loading ,
3716
- previousData : undefined ,
3717
- variables : { } ,
3718
- } ) ;
3719
- }
3720
-
3721
- {
3722
- const result = await takeSnapshot ( ) ;
3723
-
3724
- expect ( result ) . toEqualQueryResult ( {
3725
- data : undefined ,
3726
- error : new ApolloError ( { graphQLErrors : [ { message : "error" } ] } ) ,
3727
- // TODO: Why does this only populate when errorPolicy is "all"?
3728
- errors : [ { message : "error" } ] ,
3729
- called : true ,
3730
- loading : false ,
3731
- networkStatus : NetworkStatus . error ,
3732
- previousData : undefined ,
3733
- variables : { } ,
3734
- } ) ;
3735
- }
3736
-
3737
- expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
3738
- expect ( onError ) . toHaveBeenCalledWith (
3739
- new ApolloError ( { graphQLErrors : [ new GraphQLError ( "error" ) ] } )
3740
- ) ;
3741
-
3742
- await expect ( takeSnapshot ) . not . toRerender ( ) ;
3743
- } ) ;
3744
-
3745
3615
it ( 'returns partial data when returning GraphQL errors while using an `errorPolicy` set to "all"' , async ( ) => {
3746
3616
const query = gql `
3747
3617
{
@@ -3804,181 +3674,6 @@ describe("useQuery Hook", () => {
3804
3674
await expect ( takeSnapshot ) . not . toRerender ( ) ;
3805
3675
} ) ;
3806
3676
3807
- it ( 'calls `onError` but not `onCompleted` when returning partial data with GraphQL errors while using an `errorPolicy` set to "all"' , async ( ) => {
3808
- const query = gql `
3809
- {
3810
- hello
3811
- }
3812
- ` ;
3813
- const mocks = [
3814
- {
3815
- request : { query } ,
3816
- result : {
3817
- data : { hello : null } ,
3818
- errors : [ new GraphQLError ( 'Could not fetch "hello"' ) ] ,
3819
- } ,
3820
- } ,
3821
- ] ;
3822
-
3823
- const cache = new InMemoryCache ( ) ;
3824
- const wrapper = ( { children } : any ) => (
3825
- < MockedProvider mocks = { mocks } cache = { cache } >
3826
- { children }
3827
- </ MockedProvider >
3828
- ) ;
3829
-
3830
- const onError = jest . fn ( ) ;
3831
- const onCompleted = jest . fn ( ) ;
3832
- using _disabledAct = disableActEnvironment ( ) ;
3833
- const { takeSnapshot } = await renderHookToSnapshotStream (
3834
- ( ) => useQuery ( query , { onError, onCompleted, errorPolicy : "all" } ) ,
3835
- { wrapper }
3836
- ) ;
3837
-
3838
- {
3839
- const result = await takeSnapshot ( ) ;
3840
-
3841
- expect ( result ) . toEqualQueryResult ( {
3842
- data : undefined ,
3843
- called : true ,
3844
- loading : true ,
3845
- networkStatus : NetworkStatus . loading ,
3846
- previousData : undefined ,
3847
- variables : { } ,
3848
- } ) ;
3849
- }
3850
-
3851
- {
3852
- const result = await takeSnapshot ( ) ;
3853
-
3854
- expect ( result ) . toEqualQueryResult ( {
3855
- data : { hello : null } ,
3856
- error : new ApolloError ( {
3857
- graphQLErrors : [ { message : 'Could not fetch "hello"' } ] ,
3858
- } ) ,
3859
- errors : [ { message : 'Could not fetch "hello"' } ] ,
3860
- called : true ,
3861
- loading : false ,
3862
- networkStatus : NetworkStatus . error ,
3863
- previousData : undefined ,
3864
- variables : { } ,
3865
- } ) ;
3866
- }
3867
-
3868
- expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
3869
- expect ( onError ) . toHaveBeenCalledWith (
3870
- new ApolloError ( {
3871
- graphQLErrors : [ new GraphQLError ( 'Could not fetch "hello"' ) ] ,
3872
- } )
3873
- ) ;
3874
- expect ( onCompleted ) . not . toHaveBeenCalled ( ) ;
3875
-
3876
- await expect ( takeSnapshot ) . not . toRerender ( ) ;
3877
- } ) ;
3878
-
3879
- it ( "calls `onError` a single time when refetching returns a successful result" , async ( ) => {
3880
- const query = gql `
3881
- {
3882
- hello
3883
- }
3884
- ` ;
3885
- const mocks = [
3886
- {
3887
- request : { query } ,
3888
- result : {
3889
- errors : [ new GraphQLError ( "error" ) ] ,
3890
- } ,
3891
- } ,
3892
- {
3893
- request : { query } ,
3894
- result : {
3895
- data : { hello : "world" } ,
3896
- } ,
3897
- delay : 10 ,
3898
- } ,
3899
- ] ;
3900
-
3901
- const cache = new InMemoryCache ( ) ;
3902
- const wrapper = ( { children } : any ) => (
3903
- < MockedProvider mocks = { mocks } cache = { cache } >
3904
- { children }
3905
- </ MockedProvider >
3906
- ) ;
3907
-
3908
- const onError = jest . fn ( ) ;
3909
- using _disabledAct = disableActEnvironment ( ) ;
3910
- const { takeSnapshot, getCurrentSnapshot } =
3911
- await renderHookToSnapshotStream (
3912
- ( ) =>
3913
- useQuery ( query , {
3914
- onError,
3915
- notifyOnNetworkStatusChange : true ,
3916
- } ) ,
3917
- { wrapper }
3918
- ) ;
3919
-
3920
- {
3921
- const result = await takeSnapshot ( ) ;
3922
-
3923
- expect ( result ) . toEqualQueryResult ( {
3924
- data : undefined ,
3925
- called : true ,
3926
- loading : true ,
3927
- networkStatus : NetworkStatus . loading ,
3928
- previousData : undefined ,
3929
- variables : { } ,
3930
- } ) ;
3931
- }
3932
-
3933
- {
3934
- const result = await takeSnapshot ( ) ;
3935
-
3936
- expect ( result ) . toEqualQueryResult ( {
3937
- data : undefined ,
3938
- error : new ApolloError ( { graphQLErrors : [ { message : "error" } ] } ) ,
3939
- called : true ,
3940
- loading : false ,
3941
- networkStatus : NetworkStatus . error ,
3942
- previousData : undefined ,
3943
- variables : { } ,
3944
- } ) ;
3945
- }
3946
-
3947
- expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
3948
-
3949
- void getCurrentSnapshot ( ) . refetch ( ) ;
3950
-
3951
- {
3952
- const result = await takeSnapshot ( ) ;
3953
-
3954
- expect ( result ) . toEqualQueryResult ( {
3955
- data : undefined ,
3956
- called : true ,
3957
- loading : true ,
3958
- networkStatus : NetworkStatus . refetch ,
3959
- previousData : undefined ,
3960
- variables : { } ,
3961
- } ) ;
3962
- }
3963
-
3964
- {
3965
- const result = await takeSnapshot ( ) ;
3966
-
3967
- expect ( result ) . toEqualQueryResult ( {
3968
- data : { hello : "world" } ,
3969
- called : true ,
3970
- loading : false ,
3971
- networkStatus : NetworkStatus . ready ,
3972
- previousData : undefined ,
3973
- variables : { } ,
3974
- } ) ;
3975
- }
3976
-
3977
- expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
3978
-
3979
- await expect ( takeSnapshot ) . not . toRerender ( ) ;
3980
- } ) ;
3981
-
3982
3677
it ( "should persist errors on re-render if they are still valid" , async ( ) => {
3983
3678
const query = gql `
3984
3679
{
0 commit comments