Skip to content

Commit

Permalink
Add tests and add dev dependencies to package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardofbarros committed Jun 17, 2014
1 parent 4b15a00 commit dcf422e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -28,6 +28,10 @@
"xtend" : "2.1.x",
"validator" : "3.10.x"
},
"devDependencies": {
"mocha": "1.18.x",
"expect.js" : "0.3.x"
},
"engines": {
"node": ">= 0.8"
}
Expand Down
28 changes: 28 additions & 0 deletions test/extend.js
@@ -0,0 +1,28 @@
// Dependencies
var expect = require('expect.js')
, mongules = require('./../index');

// Start extend tests
describe('Extend validator', function() {
it('Should add new validation', function(done_add) {
mongules.extend('hasNumber', function(str) {
return /[0-9]/.test(str);
});

done_add();
});

it('Should validate with the new validation fn', function(done_validate) {
expect(mongules.hasNumber(1)).to.be(true);

expect(mongules.hasNumber('string')).to.be(false);

done_validate();
});

it('Should hook a message to new validation fn', function(done_hook) {
mongules.hookMsg('hasNumber', 'extended-hook-msg');
expect(mongules._msgHooks.hasNumber).to.be.equal('extended-hook-msg');
done_hook();
});
});
4 changes: 4 additions & 0 deletions test/has-validations.js
@@ -0,0 +1,4 @@
/*
* To write some tests in the near future
*/

36 changes: 36 additions & 0 deletions test/msg-hooks.js
@@ -0,0 +1,36 @@
// Dependencies
var expect = require('expect.js')
, mongules = require('./../index');

// Start messages hooks tests
describe('Message Hook(s)', function() {
it('Should hook a message to isNumeric', function(done_hook) {
mongules.hookMsg('isNumeric', 'single-hook-msg');

expect(mongules._msgHooks.isNumeric).to.be.equal('single-hook-msg');

done_hook();
});

it('Should hook different messages to isInt and isNull', function(done_hook) {
mongules.hookMsg({
'isInt' : 'isInt-hook-msg',
'isNull' : 'isNull-hook-msg'
});

expect(mongules._msgHooks.isInt).to.be.equal('isInt-hook-msg');
expect(mongules._msgHooks.isNull).to.be.equal('isNull-hook-msg');

done_hook();
});

it('Should hook the same message to isEmail, isAlpha and isAlphanumeric', function(done_hook) {
mongules.hookMsg(['isEmail', 'isAlpha', 'isAlphanumeric'], 'multiple-hook-msg');

expect(mongules._msgHooks.isEmail).to.be.equal('multiple-hook-msg');
expect(mongules._msgHooks.isAlpha).to.be.equal('multiple-hook-msg');
expect(mongules._msgHooks.isAlphanumeric).to.be.equal('multiple-hook-msg');

done_hook();
});
});
3 changes: 3 additions & 0 deletions test/validator.js
@@ -0,0 +1,3 @@
// Import test from validator

require('validator/test/validators');

0 comments on commit dcf422e

Please sign in to comment.