-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.ts
More file actions
67 lines (60 loc) · 1.78 KB
/
jest.setup.ts
File metadata and controls
67 lines (60 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { LoggerI } from './src/logger/interface';
import { OpenAPIFileT } from './src/openapi';
expect.extend({
toBeCalledLoggerMethod(actual: any, messageRegExp: RegExp, count?: number) {
const expectedCount = typeof count === 'number' ? count : 1;
let actualCount = 0;
const calls = actual?.mock?.calls || [];
calls.forEach((parameters: Array<any>) => {
parameters.forEach((parameter: any) => {
if (typeof parameter === 'string' && messageRegExp.test(parameter)) {
actualCount++;
}
});
});
const pass = actualCount === expectedCount;
return {
pass,
message: pass
? () => `expected number of logger method calls ${actualCount} not to be ${expectedCount} with message like "${messageRegExp}"`
: () => `expected number of logger method calls ${actualCount} to be ${expectedCount} with message like "${messageRegExp}"`,
};
},
});
global.createFakeLogger = () => {
const logger: LoggerI = {
trace: jest.fn(() => {}),
info: jest.fn(() => {}),
notImportantWarning: jest.fn(() => {}),
warning: jest.fn(() => {}),
error: jest.fn(() => {}),
errorMessage: jest.fn(() => {}),
success: jest.fn(() => {}),
helpInfo: jest.fn(() => {}),
clone: jest.fn(() => {
return logger;
}),
getHelpInfo: jest.fn(() => ''),
};
return logger;
};
global.createFakeOpenAPIFile = (document: Partial<OpenAPIFileT['document']>): OpenAPIFileT => {
return {
context: {
sourcePath: '',
sourceExtension: '.json',
},
// @ts-expect-error wrong OpenAPI type
document: {
openapi: '3.0.0',
info: {
version: '1.0.0',
title: 'Fake Test OpenAPI',
license: {
name: 'MIT',
},
},
...document,
},
};
};