1
1
/* eslint-disable @typescript-eslint/no-empty-function */
2
2
/* eslint-disable @typescript-eslint/no-var-requires */
3
3
/* eslint-disable max-classes-per-file */
4
- const timeJumpRequire = require ( '../timeJump' ) ;
4
+ import timeJumpRequire from '../timeJump' ;
5
5
6
6
class Component {
7
+ mockfn : ( state ) => void
8
+
9
+ state : Record < string , unknown >
10
+
7
11
constructor ( mockfn ) {
8
12
this . mockfn = mockfn ;
9
13
}
@@ -15,6 +19,12 @@ class Component {
15
19
}
16
20
17
21
class FiberNode {
22
+ private state : Record < null , unknown > ;
23
+
24
+ children : FiberNode [ ] ;
25
+
26
+ component : Component
27
+
18
28
constructor ( mockfn , state ) {
19
29
this . state = state ;
20
30
this . children = [ ] ;
@@ -23,8 +33,8 @@ class FiberNode {
23
33
}
24
34
25
35
describe ( 'unit testing for timeJump.js' , ( ) => {
26
- let timeJump ;
27
- let snapShot ;
36
+ let timeJump : ( target ) => void ;
37
+ let snapShot : Record < string , FiberNode > ;
28
38
let mode ;
29
39
let mockFuncs ;
30
40
@@ -33,11 +43,11 @@ describe('unit testing for timeJump.js', () => {
33
43
mockFuncs = [ ] ;
34
44
for ( let i = 0 ; i < 4 ; i += 1 ) mockFuncs . push ( jest . fn ( ) ) ;
35
45
36
- const tree = new FiberNode ( mockFuncs [ 0 ] ) ;
46
+ const tree : FiberNode = new FiberNode ( mockFuncs [ 0 ] , '*' ) ;
37
47
tree . children = [
38
- new FiberNode ( mockFuncs [ 1 ] ) ,
39
- new FiberNode ( mockFuncs [ 2 ] ) ,
40
- new FiberNode ( mockFuncs [ 3 ] ) ,
48
+ new FiberNode ( mockFuncs [ 1 ] , '*' ) ,
49
+ new FiberNode ( mockFuncs [ 2 ] , '*' ) ,
50
+ new FiberNode ( mockFuncs [ 3 ] , '*' ) ,
41
51
] ;
42
52
43
53
snapShot = { tree } ;
@@ -57,7 +67,7 @@ describe('unit testing for timeJump.js', () => {
57
67
new FiberNode ( null , states [ 3 ] ) ,
58
68
] ;
59
69
60
- beforeEach ( ( ) => {
70
+ beforeEach ( ( ) : void => {
61
71
timeJump ( target ) ;
62
72
} ) ;
63
73
test ( 'timeJump should call setState on each state in origin' , ( ) => {
@@ -73,7 +83,7 @@ describe('unit testing for timeJump.js', () => {
73
83
const logMode = jest . fn ( ) ;
74
84
logMode . mockImplementation ( ( ) => expect ( mode . jumping ) . toBe ( true ) ) ;
75
85
76
- snapShot . tree = new FiberNode ( logMode ) ;
86
+ snapShot . tree = new FiberNode ( logMode , null ) ;
77
87
const target = new FiberNode ( null , 'test' ) ;
78
88
timeJump ( target ) ;
79
89
expect ( logMode ) . toHaveBeenCalled ( ) ;
0 commit comments