Total Complexity | 6 |
Complexity/F | 1.5 |
Lines of Code | 40 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { assert } from 'chai'; |
||
2 | import { Decorator } from '../entry'; |
||
3 | import Logger from '../Logger'; |
||
4 | import { verifyStdout } from '../utils'; |
||
5 | |||
6 | suite('Params'); |
||
7 | |||
8 | test('Positive: function paramsLevel', function () { |
||
9 | const logger = new Logger(); |
||
10 | const decorator = new Decorator({ logger, paramsLevel: 'verbose' }); |
||
11 | |||
12 | const decorated = decorator()(function x(n) { |
||
13 | if (n > 0) return n * 2; |
||
|
|||
14 | |||
15 | return n; |
||
16 | }); |
||
17 | |||
18 | assert.equal(decorated(4), 8); |
||
19 | assert.isNotEmpty(logger.stack.verbose); |
||
20 | verifyStdout(logger, { params: '[ 4 ]', result: '8' }, { level: 'info' }); |
||
21 | verifyStdout(logger, { method: 'x', params: '[ 4 ]' }, { level: 'verbose' }); |
||
22 | }); |
||
23 | |||
24 | |||
25 | test('Negative: function paramsLevel', function () { |
||
26 | const logger = new Logger(); |
||
27 | const decorator = new Decorator({ logger }); |
||
28 | |||
29 | const decorated = decorator()(function (n) { |
||
30 | if (n > 0) return n * 2; |
||
31 | |||
32 | return n; |
||
33 | }); |
||
34 | |||
35 | assert.equal(decorated(4), 8); |
||
36 | |||
37 | verifyStdout(logger, { params: '[ 4 ]', result: '8' }, { level: 'info' }); |
||
38 | |||
39 | assert.isEmpty(logger.stack.verbose); |
||
40 | }); |
||
41 |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.