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

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 36
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 24
mnd 0
bc 0
fnc 5
dl 0
loc 36
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10
1
import { RuleTester } from '../utils';
2
3
const tester = new RuleTester('integer');
4
5
suite('Rules: integer');
6
7
test('Positive: numbers', function () {
8
    tester.positive(1, 1);
9
    tester.positive(-3874, -3874);
10
    tester.positive(0, 0);
11
    tester.positive(1e+7, 1e+7);
12
});
13
14
test('Positive: string', function () {
15
    tester.positive('5', 5);
16
    tester.positive('6.0', 6);
17
    tester.positive('-34', -34);
18
});
19
20
test('Positive: empty value', function () {
21
    tester.positive(null, null);
22
    tester.positive(undefined, undefined);
23
});
24
25
test('Negative: numbers', function () {
26
    tester.negative(Number.NaN, 'NOT_NUMBER', 'The value is not a number or could not be cast to a number');
27
    tester.negative(0.5, 'NOT_INTEGER', 'The number is not a valid integer');
28
    tester.negative(-432.9, 'NOT_INTEGER', 'The number is not a valid integer');
29
});
30
31
test('Negative: bad formats', function () {
32
    tester.negative({ object: 1 }, 'NOT_NUMBER', 'The value is not a number or could not be cast to a number');
33
    tester.negative(false, 'NOT_NUMBER', 'The value is not a number or could not be cast to a number');
34
    tester.negative(true, 'NOT_NUMBER', 'The value is not a number or could not be cast to a number');
35
    tester.negative('fkdsfdsfkds', 'NOT_NUMBER', 'The value is not a number or could not be cast to a number');
36
});
37