@incdevco/framework
Version:
node.js lambda framework
109 lines (64 loc) • 2.04 kB
JavaScript
var Expect = require('chai').expect;
var Validator = require('./index');
describe('framework/validators/length', function () {
'use strict';
var input, validator;
beforeEach(function () {
input = undefined;
validator = new Validator({
maximum: 6,
minimum: 3
});
});
it('should resolve when submitted value is less than specified maximum and greater then specified minimum', function (done) {
input = 'string';
validator.validate(input)
.then(function (actual) {
Expect(actual).to.equal(true, 'actual');
done();
})
.catch(done);
});
it('should resolve when submitted value is less than specified maximum', function (done) {
input = 'string';
validator = new Validator({
maximum: 6
});
validator.validate(input)
.then(function (actual) {
Expect(actual).to.equal(true, 'actual');
done();
})
.catch(done);
});
it('should reject when submitted value is less than minimum', function (done) {
input = 't';
validator = new Validator({
minimum: 3
});
validator.validate(input)
.then(function () {
throw new Error('resolved');
})
.catch(function (exception) {
Expect(exception.message).to.equal('Must be at least 3 characters long.', 'exception.message');
done();
})
.catch(done);
});
it('should reject when submitted value is greater than maximum', function (done) {
input = 'this is to long';
validator = new Validator({
maximum: 6
});
validator.validate(input)
.then(function () {
throw new Error('resolved');
})
.catch(function (exception) {
Expect(exception.message).to.equal('Must be less than 6 characters long.', 'exception.message');
done();
})
.catch(done);
});
});