Skip to content

Commit 8c6682a

Browse files
committed
Add func validator tests
1 parent d7cd31a commit 8c6682a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

lib/validators/func.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ function isValid(data, model) {
1111
return true;
1212
}
1313

14+
if(typeof model.func !== 'function') {
15+
return false;
16+
}
17+
1418
return model.func(data);
1519
}
1620

spec/validators/func.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const valid = require('../../lib/validators/func');
2+
3+
4+
5+
describe(' - Function validator', () => {
6+
7+
8+
it('shall be a function', () => {
9+
expect(typeof valid).toEqual('function');
10+
});
11+
12+
describe('is a valid function', () => {
13+
const model = {};
14+
15+
beforeEach(function () {
16+
model.func = function (data) {
17+
return !!data;
18+
};
19+
20+
spyOn(model, 'func').and.callThrough();
21+
});
22+
23+
it('shall call the function after execution', () => {
24+
expect(model.func).not.toHaveBeenCalled();
25+
valid('null', model);
26+
expect(model.func).toHaveBeenCalled();
27+
});
28+
});
29+
30+
describe('is NOT a valid function', () => {
31+
const model = {};
32+
33+
beforeEach(function () {
34+
model.func = 'invalidData';
35+
});
36+
37+
it('shall return false', () => {
38+
const result = valid('null', model);
39+
expect(result).toEqual(false);
40+
});
41+
});
42+
});

0 commit comments

Comments
 (0)