Skip to content

Commit 28aa820

Browse files
committed
type validator tests
1 parent fcc710a commit 28aa820

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

spec/validators/type.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var valid = require('../../lib/validators/type');
2+
3+
const str = 'Hello world';
4+
const obj = {hello: 'world'};
5+
const num = 42;
6+
7+
const types = {
8+
string: str,
9+
object: obj,
10+
number: num
11+
};
12+
13+
const typesKeys = Object.keys(types);
14+
15+
describe(' - Type validator', () => {
16+
it('shall be a function', () => {
17+
expect(typeof valid).toEqual('function');
18+
});
19+
20+
21+
for (let key in typesKeys) {
22+
it('shall validate '+ typesKeys[key] +' when no model set', () => {
23+
expect(valid(types[key], {})).toEqual(true);
24+
});
25+
}
26+
27+
for (let validType in typesKeys) {
28+
let model = {type: typesKeys[validType]};
29+
for (let check in typesKeys) {
30+
it('shall only validate '+ typesKeys[validType] +' when model set, and '+ typesKeys[check] +' given', () => {
31+
expect(valid(types[typesKeys[check]], model)).toEqual( (validType === check) );
32+
});
33+
}
34+
}
35+
36+
});

0 commit comments

Comments
 (0)