-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaxSize.test.js
54 lines (43 loc) · 1.99 KB
/
maxSize.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
const expect = require('chai').expect;
const validators = require('../src/common-validators');
describe('maxSize', function() {
it('empty is valid', function() {
expect(validators.maxSize(undefined, 5)).to.be.undefined;
});
it('size less then max is valid', function() {
expect(validators.maxSize('я ♥ you', 11)).to.be.undefined;
});
it('size more then max is invalid', function() {
expect(validators.maxSize('я ♥ you', 9)).to.have.property('error');
});
it('size equal max is valid', function() {
expect(validators.maxSize('я ♥ you', 10)).to.be.undefined;
});
it('number is correct value', function() {
expect(validators.maxSize(12345, 5)).to.be.undefined;
expect(validators.maxSize(12345, 4)).to.have.property('error');
});
it('unicode string is correct value', function() {
expect(validators.maxSize('\u0041\u0042\u0043\u0044', 5)).to.be.undefined;
expect(validators.maxSize('\u0041\u0042\u0043\u0044\u0045\u0046', 5)).to.have.property('error');
});
it('array is correct value', function() {
expect(validators.maxSize(['я', '♥', 'you'], 18)).to.be.undefined;
expect(validators.maxSize(['я', '♥', 'you'], 17)).to.have.property('error');
});
it('object is correct value', function() {
expect(validators.maxSize({a: 'я', b: '♥', c: 'you'}, 30)).to.be.undefined;
expect(validators.maxSize({a: 'я', b: '♥', c: 'you'}, 29)).to.have.property('error');
});
it('custom stringify method', function() {
function toString(value) {
if (typeof value.toString === 'function') {
return value.toString();
}
return JSON.stringify(value);
}
expect(validators.maxSize(['я', '♥', 'you'], 10, {stringify: toString})).to.be.undefined;
expect(validators.maxSize(['я', '♥', 'you'], 9, {stringify: toString})).to.have.property('error');
});
});