Skip to content

Commit d6dbf68

Browse files
committed
changed timejump and timejump test to ts files and typed some variables
1 parent 89eb2df commit d6dbf68

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/backend/__tests__/timeJump.test.js renamed to src/backend/__tests__/timeJump.test.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/* eslint-disable @typescript-eslint/no-empty-function */
22
/* eslint-disable @typescript-eslint/no-var-requires */
33
/* eslint-disable max-classes-per-file */
4-
const timeJumpRequire = require('../timeJump');
4+
import timeJumpRequire from '../timeJump';
55

66
class Component {
7+
mockfn: (state) => void
8+
9+
state: Record<string, unknown>
10+
711
constructor(mockfn) {
812
this.mockfn = mockfn;
913
}
@@ -15,6 +19,12 @@ class Component {
1519
}
1620

1721
class FiberNode {
22+
private state: Record<null, unknown>;
23+
24+
children: FiberNode[];
25+
26+
component: Component
27+
1828
constructor(mockfn, state) {
1929
this.state = state;
2030
this.children = [];
@@ -23,8 +33,8 @@ class FiberNode {
2333
}
2434

2535
describe('unit testing for timeJump.js', () => {
26-
let timeJump;
27-
let snapShot;
36+
let timeJump: (target) => void;
37+
let snapShot: Record<string, FiberNode>;
2838
let mode;
2939
let mockFuncs;
3040

@@ -33,11 +43,11 @@ describe('unit testing for timeJump.js', () => {
3343
mockFuncs = [];
3444
for (let i = 0; i < 4; i += 1) mockFuncs.push(jest.fn());
3545

36-
const tree = new FiberNode(mockFuncs[0]);
46+
const tree: FiberNode = new FiberNode(mockFuncs[0], '*');
3747
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], '*'),
4151
];
4252

4353
snapShot = { tree };
@@ -57,7 +67,7 @@ describe('unit testing for timeJump.js', () => {
5767
new FiberNode(null, states[3]),
5868
];
5969

60-
beforeEach(() => {
70+
beforeEach((): void => {
6171
timeJump(target);
6272
});
6373
test('timeJump should call setState on each state in origin', () => {
@@ -73,7 +83,7 @@ describe('unit testing for timeJump.js', () => {
7383
const logMode = jest.fn();
7484
logMode.mockImplementation(() => expect(mode.jumping).toBe(true));
7585

76-
snapShot.tree = new FiberNode(logMode);
86+
snapShot.tree = new FiberNode(logMode, null);
7787
const target = new FiberNode(null, 'test');
7888
timeJump(target);
7989
expect(logMode).toHaveBeenCalled();
File renamed without changes.

0 commit comments

Comments
 (0)