src/__tests__/action.js   A
last analyzed

Complexity

Total Complexity 16
Complexity/F 1

Size

Lines of Code 70
Function Count 16

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 16
eloc 43
mnd 0
bc 0
fnc 16
dl 0
loc 70
rs 10
bpm 0
cpm 1
noi 6
c 0
b 0
f 0
1
import * as nAutoMetrics from '@financial-times/n-auto-metrics';
2
3
import setupMonitor from '../setup';
4
import { monitorService, monitorModule } from '../action';
5
6
jest.mock('@financial-times/n-auto-metrics', () => ({
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
7
	tagService: () => inputFunction => inputFunction,
8
	metricsAction: jest.fn(inputFunction => inputFunction),
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
	initAutoMetrics: jest.fn(),
10
}));
11
12
describe('monitorService', () => {
13
	afterEach(() => {
14
		jest.clearAllMocks();
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
15
	});
16
17
	const app = {
18
		use: jest.fn(),
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
19
	};
20
21
	const metrics = {};
22
23
	it('disable metricsAction if metrics instance is not set', () => {
24
		setupMonitor({ app });
25
		const serviceActions = {
26
			method: () => {},
27
		};
28
		monitorService('mock-service', serviceActions);
29
		expect(nAutoMetrics.metricsAction.mock.calls).toMatchSnapshot();
30
	});
31
32
	it('enable metricsAction if metrics instance is set', () => {
33
		setupMonitor({ app, metrics });
34
		const serviceActions = {
35
			method: () => {},
36
		};
37
		monitorService('mock-service', serviceActions);
38
		expect(nAutoMetrics.metricsAction.mock.calls).toMatchSnapshot();
39
	});
40
});
41
42
describe('monitorModule', () => {
43
	afterEach(() => {
44
		jest.clearAllMocks();
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
45
	});
46
47
	const app = {
48
		use: jest.fn(),
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
49
	};
50
51
	const metrics = {};
52
53
	it('disable metricsAction if metrics instance is not set', () => {
54
		setupMonitor({ app });
55
		const moduleFunctions = {
56
			method: () => {},
57
		};
58
		monitorModule(moduleFunctions);
59
		expect(nAutoMetrics.metricsAction.mock.calls).toMatchSnapshot();
60
	});
61
62
	it('enable metricsAction if metrics instance is set', () => {
63
		setupMonitor({ app, metrics });
64
		const moduleFunctions = {
65
			method: () => {},
66
		};
67
		monitorModule(moduleFunctions);
68
		expect(nAutoMetrics.metricsAction.mock.calls).toMatchSnapshot();
69
	});
70
});
71