1
- import { useAsync , UseAsyncReturn } from '../src' ;
1
+ import { useAsync } from '../src' ;
2
2
import { renderHook } from '@testing-library/react-hooks' ;
3
3
4
4
interface StarwarsHero {
5
5
name : string ;
6
6
}
7
7
8
- type StarwarsHeroArgs = {
9
- asyncFunction : ( ) => Promise < StarwarsHero [ ] > ;
10
- } ;
11
-
12
8
export const generateMockResponseData = ( amount : number = 5 ) : StarwarsHero [ ] =>
13
9
[ ...Array ( amount ) . keys ( ) ] . map ( n => ( {
14
10
id : n + 1 ,
@@ -26,11 +22,8 @@ describe('useAync', () => {
26
22
const onSuccess = jest . fn ( ) ;
27
23
const onError = jest . fn ( ) ;
28
24
29
- const { result, waitForNextUpdate } = renderHook <
30
- StarwarsHeroArgs ,
31
- UseAsyncReturn < StarwarsHero [ ] >
32
- > ( ( ) =>
33
- useAsync < StarwarsHero [ ] , any > (
25
+ const { result, waitForNextUpdate } = renderHook ( ( ) =>
26
+ useAsync (
34
27
async ( ) => {
35
28
return Promise . resolve ( fakeResults ) ;
36
29
} ,
@@ -57,11 +50,8 @@ describe('useAync', () => {
57
50
const onSuccess = jest . fn ( ) ;
58
51
const onError = jest . fn ( ) ;
59
52
60
- const { result, waitForNextUpdate } = renderHook <
61
- StarwarsHeroArgs ,
62
- UseAsyncReturn < StarwarsHero [ ] >
63
- > ( ( ) =>
64
- useAsync < StarwarsHero [ ] , any > (
53
+ const { result, waitForNextUpdate } = renderHook ( ( ) =>
54
+ useAsync (
65
55
async ( ) => {
66
56
return Promise . reject ( new Error ( 'something went wrong' ) ) ;
67
57
} ,
0 commit comments