File tree 6 files changed +259
-30
lines changed
6 files changed +259
-30
lines changed Original file line number Diff line number Diff line change 39
39
"scripts" : {
40
40
"start" : " tsdx watch" ,
41
41
"build" : " tsdx build" ,
42
- "test" : " tsdx test --env=jsdom"
42
+ "test" : " tsdx --tsconfig ./tsconfig.test.json test --env=jsdom"
43
43
},
44
44
"peerDependencies" : {
45
45
"react" : " >=16.8"
55
55
"singleQuote" : true ,
56
56
"trailingComma" : " es5"
57
57
},
58
+ "jest" : {
59
+ "globals" : {
60
+ "ts-jest" : {
61
+ "tsConfig" : " tsconfig.test.json"
62
+ }
63
+ },
64
+ "setupFilesAfterEnv" : [
65
+ " <rootDir>/test/setupTests.ts"
66
+ ]
67
+ },
58
68
"devDependencies" : {
69
+ "@testing-library/react" : " ^9.3.0" ,
70
+ "@testing-library/react-hooks" : " ^3.1.0" ,
59
71
"@types/jest" : " ^24.0.12" ,
60
- "@types/react" : " ^16.8.16 " ,
61
- "@types/react-dom" : " ^16.8.4 " ,
72
+ "@types/react" : " ^16.9.9 " ,
73
+ "@types/react-dom" : " ^16.9.2 " ,
62
74
"husky" : " ^2.2.0" ,
75
+ "jest-fetch-mock" : " ^2.1.2" ,
63
76
"prettier" : " ^1.17.0" ,
64
77
"pretty-quick" : " ^1.10.0" ,
65
- "react" : " ^16.8.6" ,
66
- "react-dom" : " ^16.8.6" ,
78
+ "react" : " ^16.10.2" ,
79
+ "react-dom" : " ^16.10.2" ,
80
+ "react-test-renderer" : " ^16.10.2" ,
67
81
"tsdx" : " ^0.7.2" ,
68
82
"tslib" : " ^1.9.3" ,
69
83
"typescript" : " ^3.4.5"
Original file line number Diff line number Diff line change
1
+ import { GlobalWithFetchMock } from 'jest-fetch-mock' ;
2
+
3
+ const customGlobal : GlobalWithFetchMock = global as GlobalWithFetchMock ;
4
+ customGlobal . fetch = require ( 'jest-fetch-mock' ) ;
5
+ customGlobal . fetchMock = customGlobal . fetch ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { useAsync } from '../src' ;
2
+ import { cleanup } from '@testing-library/react' ;
3
+ import { FetchMock } from 'jest-fetch-mock/types' ;
4
+
5
+ const fetch : FetchMock = global . fetch ;
6
+
7
+ interface StarwarsHero {
8
+ name : string ;
9
+ }
10
+
11
+ export const generateMockResponseData = ( amount : number = 5 ) : StarwarsHero [ ] =>
12
+ [ ...Array ( amount ) . keys ( ) ] . map ( n => ( {
13
+ id : n + 1 ,
14
+ name : `Starwars Hero ${ n + 1 } ` ,
15
+ } ) ) ;
16
+
17
+ describe ( 'useAync' , ( ) => {
18
+ afterEach ( cleanup ) ;
19
+
20
+ beforeEach ( ( ) => {
21
+ fetch . resetMocks ( ) ;
22
+ } ) ;
23
+
24
+ it ( 'should have a useAsync hook' , ( ) => {
25
+ expect ( useAsync ) . toBeDefined ( ) ;
26
+ } ) ;
27
+
28
+ // it('should set loading flag when request is initially made', () => {
29
+
30
+ // });
31
+ } ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "extends" : " ./tsconfig.json" ,
3
+ "compilerOptions" : {
4
+ "downlevelIteration" : true
5
+ },
6
+ "include" : [" src/**/*.ts" , " test/**/*.ts" ]
7
+ }
You can’t perform that action at this time.
0 commit comments