forked from mikeerickson/validatorjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mikeerickson#129 from richriscunha/sometimes-feature
add sometimes feature including tests
- Loading branch information
Showing
5 changed files
with
147 additions
and
4 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,67 @@ | ||
if (typeof require !== 'undefined') { | ||
var Validator = require('../src/validator.js'); | ||
var expect = require('chai').expect; | ||
} else { | ||
var Validator = window.Validator; | ||
var expect = window.chai.expect; | ||
} | ||
|
||
describe('sometimes validation pass rules', function() { | ||
it('should pass when the property is passed with data', function() { | ||
var validator = new Validator({ | ||
firstname: 'Johnny', | ||
lastname: 'Appleseed' | ||
}, { | ||
firstname: 'required', | ||
lastname: 'required|sometimes' | ||
}); | ||
expect(validator.passes()).to.be.true; | ||
}); | ||
|
||
it('should pass when the property is not passed with data', function() { | ||
var validator = new Validator({ | ||
firstname: 'Johnny' | ||
}, { | ||
firstname: 'required', | ||
lastname: 'required|sometimes' | ||
}); | ||
expect(validator.passes()).to.be.true; | ||
}); | ||
|
||
it('should be able to register and pass async rule when the property is passed with data', function(done) { | ||
Validator.registerAsync('username', function(desiredUsername, ruleValue, attribute, passes) { | ||
setTimeout(function() { | ||
if (desiredUsername == 'test') { | ||
passes(); | ||
} | ||
}, 50); | ||
}, ':attribute is an invalid username'); | ||
|
||
var validator = new Validator({ | ||
username: 'test', | ||
email: '[email protected]' | ||
}, { | ||
username: 'username', | ||
email: 'email|sometimes' | ||
}); | ||
validator.passes(done); | ||
}); | ||
|
||
it('should be able to register and pass async rule when the property is not passed with data', function(done) { | ||
Validator.registerAsync('username', function(desiredUsername, ruleValue, attribute, passes) { | ||
setTimeout(function() { | ||
if (desiredUsername == 'test') { | ||
passes(); | ||
} | ||
}, 50); | ||
}, ':attribute is an invalid username'); | ||
|
||
var validator = new Validator({ | ||
username: 'test' | ||
}, { | ||
username: 'username', | ||
email: 'email|sometimes' | ||
}); | ||
validator.passes(done); | ||
}); | ||
}); |
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