Skip to content

Commit d5e6c8e

Browse files
committed
test: adapt test suite to Jest v29
Jest v30.0.0 have a problems with 'unstable_mockModule'. Holding for now
1 parent a02d140 commit d5e6c8e

8 files changed

Lines changed: 817 additions & 1352 deletions

__tests__/files.service.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('File Service', () => {
7070
statSyncReturnMock = () => {
7171
throw new Error('ENOENT');
7272
};
73-
expect(() => fileService.isValidRootFolder(path)).toThrowError(
73+
expect(() => fileService.isValidRootFolder(path)).toThrow(
7474
'The path does not exist.',
7575
);
7676
});
@@ -80,7 +80,7 @@ describe('File Service', () => {
8080
isDirectory: () => false,
8181
});
8282

83-
expect(() => fileService.isValidRootFolder(path)).toThrowError(
83+
expect(() => fileService.isValidRootFolder(path)).toThrow(
8484
'The path must point to a directory.',
8585
);
8686
});
@@ -93,7 +93,7 @@ describe('File Service', () => {
9393
throw new Error();
9494
};
9595

96-
expect(() => fileService.isValidRootFolder(path)).toThrowError(
96+
expect(() => fileService.isValidRootFolder(path)).toThrow(
9797
'Cannot read the specified path.',
9898
);
9999
});
@@ -185,7 +185,7 @@ describe('File Service', () => {
185185
it('#getFileContent should read file content with utf8 encoding', () => {
186186
const path = 'file.json';
187187
fileService.getFileContent(path);
188-
expect(readFileSyncSpy).toBeCalledWith(path, 'utf8');
188+
expect(readFileSyncSpy).toHaveBeenCalledWith(path, 'utf8');
189189
});
190190

191191
xdescribe('Functional test for #deleteDir', () => {

__tests__/files.worker.service.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('FileWorkerService', () => {
9393

9494
it('should emit "explore" and parameters to the worker', () => {
9595
fileWorkerService.startScan(stream$, params);
96-
expect(messageChannelPort1Mock).toBeCalledWith({
96+
expect(messageChannelPort1Mock).toHaveBeenCalledWith({
9797
type: EVENTS.explore,
9898
value: { path: params.path },
9999
});
@@ -159,7 +159,7 @@ describe('FileWorkerService', () => {
159159
},
160160
} as WorkerMessage);
161161

162-
expect(messageChannelPort1Mock).toBeCalledWith({
162+
expect(messageChannelPort1Mock).toHaveBeenCalledWith({
163163
type: EVENTS.explore,
164164
value: { path: val[0] },
165165
});
@@ -210,15 +210,15 @@ describe('FileWorkerService', () => {
210210
fileWorkerService.startScan(stream$, params);
211211
workerEmitter.emit('error');
212212
expect(searchStatus.workerStatus).toBe('dead');
213-
}).toThrowError();
213+
}).toThrow();
214214
});
215215

216216
it('should register worker exit on "exit"', () => {
217217
fileWorkerService.startScan(stream$, params);
218218

219219
logger.info.mockReset();
220220
workerEmitter.emit('exit');
221-
expect(logger.info).toBeCalledTimes(1);
221+
expect(logger.info).toHaveBeenCalledTimes(1);
222222
});
223223
});
224224
});
@@ -240,7 +240,7 @@ describe('FileWorkerService', () => {
240240
// mockRandom(randomNumber);
241241

242242
// fileWorkerService.getSize(stream$, path);
243-
// expect(workerPostMessageMock).toBeCalledWith({
243+
// expect(workerPostMessageMock).toHaveBeenCalledWith({
244244
// type: 'start-getSize',
245245
// value: { path: path, id: randomNumber },
246246
// });

__tests__/logger.service.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ describe('LoggerService', () => {
112112
existsSyncMock.mockReturnValue(false);
113113
const path = logger.getSuggestLogFilePath();
114114
logger.saveToFile(path);
115-
expect(renameFileSyncMock).not.toBeCalled();
115+
expect(renameFileSyncMock).not.toHaveBeenCalled();
116116
});
117117

118118
it('should rotate file if exist', () => {
119119
existsSyncMock.mockReturnValue(true);
120120
const path = logger.getSuggestLogFilePath();
121121
logger.saveToFile(path);
122122
const expectedOldPath = path.replace('latest', 'old');
123-
expect(renameFileSyncMock).toBeCalledWith(path, expectedOldPath);
123+
expect(renameFileSyncMock).toHaveBeenCalledWith(path, expectedOldPath);
124124
});
125125
});
126126

@@ -136,7 +136,7 @@ describe('LoggerService', () => {
136136
'[1767225600000](info) world\n';
137137

138138
logger.saveToFile(path);
139-
expect(writeFileSyncMock).toBeCalledWith(path, expected);
139+
expect(writeFileSyncMock).toHaveBeenCalledWith(path, expected);
140140
});
141141
});
142142
});

__tests__/main.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ describe('main', () => {
5454
let servicesThatShouldNotBeCalled = [...SERVICES_MOCKS].filter(
5555
(service) => service !== serviceMock,
5656
);
57-
expect(serviceMock).toBeCalledTimes(0);
57+
expect(serviceMock).toHaveBeenCalledTimes(0);
5858
main = await import('../src/main');
59-
expect(serviceMock).toBeCalledTimes(1);
59+
expect(serviceMock).toHaveBeenCalledTimes(1);
6060
servicesThatShouldNotBeCalled.forEach((service) =>
61-
expect(service).toBeCalledTimes(0),
61+
expect(service).toHaveBeenCalledTimes(0),
6262
);
6363
};
6464

__tests__/spinner.service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Spinner Service', () => {
1414
it('should reset count', () => {
1515
const resetFn = (spinnerService.reset = jest.fn());
1616
spinnerService.setSpinner([]);
17-
expect(resetFn).toBeCalled();
17+
expect(resetFn).toHaveBeenCalled();
1818
});
1919
});
2020

__tests__/ui/results.ui.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ describe('ResultsUi', () => {
7171
resultsUi.render();
7272

7373
// With stringContaining we can ignore the terminal color codes.
74-
expect(stdoutWriteMock).toBeCalledWith(
74+
expect(stdoutWriteMock).toHaveBeenCalledWith(
7575
expect.stringContaining('path/folder/1'),
7676
);
77-
expect(stdoutWriteMock).toBeCalledWith(
77+
expect(stdoutWriteMock).toHaveBeenCalledWith(
7878
expect.stringContaining('path/folder/2'),
7979
);
8080
});
@@ -94,10 +94,10 @@ describe('ResultsUi', () => {
9494
resultsUi.render();
9595

9696
// With stringContaining we can ignore the terminal color codes.
97-
expect(stdoutWriteMock).toBeCalledWith(
97+
expect(stdoutWriteMock).toHaveBeenCalledWith(
9898
expect.stringContaining('path/folder/1'),
9999
);
100-
expect(stdoutWriteMock).not.toBeCalledWith(
100+
expect(stdoutWriteMock).not.toHaveBeenCalledWith(
101101
expect.stringContaining('path/folder/64'),
102102
);
103103
});

0 commit comments

Comments
 (0)