File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,34 @@ describe('useAync', () => {
46
46
expect ( onError ) . not . toHaveBeenCalled ( ) ;
47
47
} ) ;
48
48
49
+ // TODO legacy: should we remove this behavior?
50
+ it ( 'should resolve a successful synchronous request' , async ( ) => {
51
+ const onSuccess = jest . fn ( ) ;
52
+ const onError = jest . fn ( ) ;
53
+
54
+ const { result, waitForNextUpdate } = renderHook ( ( ) =>
55
+ useAsync (
56
+ // @ts -ignore: not allowed by TS on purpose, but still allowed at runtime
57
+ ( ) => fakeResults ,
58
+ [ ] ,
59
+ {
60
+ onSuccess : ( ) => onSuccess ( ) ,
61
+ onError : ( ) => onError ( ) ,
62
+ }
63
+ )
64
+ ) ;
65
+
66
+ expect ( result . current . loading ) . toBe ( true ) ;
67
+
68
+ await waitForNextUpdate ( ) ;
69
+
70
+ expect ( result . current . result ) . toEqual ( fakeResults ) ;
71
+ expect ( result . current . loading ) . toBe ( false ) ;
72
+ expect ( result . current . error ) . toBeUndefined ( ) ;
73
+ expect ( onSuccess ) . toHaveBeenCalled ( ) ;
74
+ expect ( onError ) . not . toHaveBeenCalled ( ) ;
75
+ } ) ;
76
+
49
77
it ( 'should set error detail for unsuccessful request' , async ( ) => {
50
78
const onSuccess = jest . fn ( ) ;
51
79
const onError = jest . fn ( ) ;
You can’t perform that action at this time.
0 commit comments