Passed
Push — master ( 7543d7...74e865 )
by Dmytro
02:50
created

tests/rules/every.test.js   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 29
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 18
mnd 0
bc 0
fnc 4
dl 0
loc 29
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1
import { RuleTester } from '../utils';
2
3
const tester = new RuleTester({ 'every': 'integer' });
4
5
suite('Rules: every');
6
7
test('Positive: valid input', function () {
8
    tester.positive([ 1 ], [ 1 ]);
9
    tester.positive([ 0, 1, 5 - 3874 ], [ 0, 1, 5 - 3874 ]);
10
});
11
12
test('Positive: cast by inner rule', function () {
13
    tester.positive([ '5' ], [ 5 ]);
14
    tester.positive([ 10, '-34', -2 ], [ 10, -34, -2 ]);
15
});
16
17
test('Negative: breaks at inner rule', function () {
18
    const nonumberMsg = 'NOT_NUMBER: The value is not a number or could not be cast to a number';
19
20
    tester.negative([ Number.NaN ],  { 0: nonumberMsg });
21
    tester.negative([ 2, 0.5, '3', 'ssss' ], { 1: 'NOT_INTEGER: The number is not a valid integer', 3: nonumberMsg });
22
});
23
24
test('Negative: bad formats', function () {
25
    tester.negative({ object: 1 }, 'NOT_ARRAY', 'The value have to be plain js array');
26
    tester.negative(false, 'NOT_ARRAY', 'The value have to be plain js array');
27
    tester.negative(true, 'NOT_ARRAY', 'The value have to be plain js array');
28
    tester.negative('fkdsfdsfkds', 'NOT_ARRAY', 'The value have to be plain js array');
29
});
30