tests/rules/max.test.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 1

Size

Lines of Code 56
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 31
mnd 0
bc 0
fnc 8
dl 0
loc 56
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10
1
import { RuleTester } from '../utils';
2
3
suite('Rules: max');
4
5
test('Positive: numbers', function () {
6
    const tester = new RuleTester([ 'number', { 'max': 5 } ]);
7
8
    tester.positive(1, 1);
9
    tester.positive(1.5, 1.5);
10
});
11
12
test('Positive: empty value', function () {
13
    const tester = new RuleTester({ 'max': 5 });
14
15
    tester.positive(null, null);
16
    tester.positive(undefined, undefined);
17
});
18
19
test('Positive: string', function () {
20
    const tester = new RuleTester([ 'string', { 'max': 20 } ]);
21
22
    tester.positive('abc', 'abc');
23
    tester.positive('-123', '-123');
24
});
25
26
test('Positive: array', function () {
27
    const tester = new RuleTester([ { 'max': 20 } ]);
28
29
    tester.positive([ 'abc' ], [ 'abc' ]);
30
    tester.positive([], []);
31
});
32
33
test('Negative: numbers', function () {
34
    const tester = new RuleTester([ 'number', { 'max': 6 } ]);
35
36
    tester.negative(110, 'TOO_HIGH', 'The number is higher than the limit', { limit: 6 });
37
    tester.negative(10.5, 'TOO_HIGH', 'The number is higher than the limit', { limit: 6 });
38
});
39
40
test('Negative: string', function () {
41
    const tester = new RuleTester([ 'string', { 'max': 3 } ]);
42
43
    tester.negative('abd1', 'TOO_LONG', 'The value is longer than the limit', { limit: 3 });
44
});
45
46
test('Negative: array', function () {
47
    const tester = new RuleTester([ { 'max': 1 } ]);
48
49
    tester.negative([ 1, 2, 3, 4 ], 'TOO_LONG', 'The value is longer than the limit', { limit: 1 });
50
});
51
52
test('Negative: bad format', function () {
53
    const tester = new RuleTester([ { 'max': 5 } ]);
54
55
    tester.negative(false, 'WRONG_FORMAT', 'Format not supported');
56
});
57