@incdevco/framework
Version:
node.js lambda framework
77 lines (45 loc) • 1.45 kB
JavaScript
var Expect = require('chai').expect;
var Validator = require('./index');
describe('framework/validators/reg-exp', function () {
'use strict';
var validator;
beforeEach(function () {
validator = new Validator({
message: 'Test Message',
regexp: new RegExp('^test$')
});
});
it('should resolve when value passes regexp', function (done) {
validator.validate('test')
.then(function (actual) {
Expect(actual).to.equal(true, 'actual');
done();
})
.catch(done);
});
it('should reject when value does not pass regexp', function (done) {
validator.validate('test&^%')
.then(function () {
throw new Error('resolved');
})
.catch(function (exception) {
Expect(exception.message).to.equal('Test Message', 'exception.message');
done();
})
.catch(done);
});
it('should reject with default message when value does not pass regexp', function (done) {
validator = new Validator({
regexp: new RegExp('^test$')
});
validator.validate('test&^%')
.then(function () {
throw new Error('resolved');
})
.catch(function (exception) {
Expect(exception.message).to.equal('Does not pass RegExp: /^test$/', 'exception.message');
done();
})
.catch(done);
});
});