-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.js
50 lines (34 loc) · 1.53 KB
/
tests.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
"use strict";
const _ = require('lodash');
const chai = require('chai'),
chaiAsPromised = require("chai-as-promised"),
expect = chai.expect;
const validator = require('./index.js');
chai.use(chaiAsPromised);
describe('Basic', function () {
it('should be an object containing methods', function() {
return expect(_.isPlainObject(validator)).to.be.true;
});
});
describe('Validator.js', function () {
it('#isAlpha should return true (valid value)', function() {
return expect(validator.isAlpha('abcdef')).to.be.true;
});
it('#isAlpha should return false (invalid value)', function() {
return expect(validator.isAlpha('abc245def')).to.be.false;
});
it('#isAlphaAsync should return a fulfilled promise (valid value)', function() {
return expect(validator.isAlphaAsync('Should be alpha', 'abcdef')).to.be.fulfilled;
});
it('#isAlphaAsync should return a rejected promise (invalid value)', function() {
return expect(validator.isAlphaAsync('Should be alpha', 'abc245def')).to.be.rejectedWith(Error);
});
});
describe('Custom validator', function () {
it('#custom should return a fulfilled promise (valid value)', function() {
return expect(validator.custom('Should starts with abc', (val, target) => { return _.startsWith(val, target); } ,'abcdef', 'abc')).to.be.fulfilled;
});
it('#custom should return a rejected promise (invalid value)', function() {
return expect(validator.custom('Should starts with abc', (val, target) => { return _.startsWith(val, target); } ,'notabc', 'abc')).to.be.rejectedWith(Error);
});
});