-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
integer.test.js
36 lines (29 loc) · 1.3 KB
/
integer.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { RuleTester } from '../utils';
const tester = new RuleTester('integer');
suite('Rules: integer');
test('Positive: numbers', function () {
tester.positive(1, 1);
tester.positive(-3874, -3874);
tester.positive(0, 0);
tester.positive(1e+7, 1e+7);
});
test('Positive: string', function () {
tester.positive('5', 5);
tester.positive('6.0', 6);
tester.positive('-34', -34);
});
test('Positive: empty value', function () {
tester.positive(null, null);
tester.positive(undefined, undefined);
});
test('Negative: numbers', function () {
tester.negative(Number.NaN, 'NOT_NUMBER', 'The value is not a number or could not be cast to a number');
tester.negative(0.5, 'NOT_INTEGER', 'The number is not a valid integer');
tester.negative(-432.9, 'NOT_INTEGER', 'The number is not a valid integer');
});
test('Negative: bad formats', function () {
tester.negative({ object: 1 }, 'NOT_NUMBER', 'The value is not a number or could not be cast to a number');
tester.negative(false, 'NOT_NUMBER', 'The value is not a number or could not be cast to a number');
tester.negative(true, 'NOT_NUMBER', 'The value is not a number or could not be cast to a number');
tester.negative('fkdsfdsfkds', 'NOT_NUMBER', 'The value is not a number or could not be cast to a number');
});