Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests and add dev dependencies to package.json
- Loading branch information
1 parent
4b15a00
commit dcf422e
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
* To write some tests in the near future | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Import test from validator | ||
|
||
require('validator/test/validators'); |