Skip to content

Commit

Permalink
tests : added test for example from docs : testing duck
Browse files Browse the repository at this point in the history
  • Loading branch information
parhelium committed Nov 14, 2014
1 parent 23119e9 commit 3eca0db
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion test/extensions/errors-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var vows = require('vows')

// Create a Test Suite
vows.describe('Testing if errors() precisely informs about the cause').addBatch({
'Object': {
'Object : ': {
topic:function(){
return {
input_invalid_boolean: {test: false},
Expand All @@ -16,6 +16,39 @@ vows.describe('Testing if errors() precisely informs about the cause').addBatch(
input_invalid_string: {test: "hello world"}
}
},
'Examples from docs':{
'Testing Duck':function(t) {

var Duck = schema({ // A duck
swim: Function, // - can swim
quack: Function, // - can quack
age: Number.min(0).max(5), // - is 0 to 5 years old
color: ['yellow', 'brown'] // - has either yellow or brown color
});
var instance = {
swim: function () { },
quack: function () { },
age: 6,
color: 'green'
}

assert(instance.age === 6, "Input is broken. Test assumes that instance.age = 6. Instance.age equal to " + instance.age)
assert(instance.color === 'green', "Input is broken. Test assumes that instance.color = 'green'. Instance.test equal to " + instance.color)

var validation = false === Duck(instance);
assert(validation, 'Validation is broken. Incorrect object '+vows.inspect(instance)+' should NOT be validated.');

var errors = Duck.errors(instance);
validation = /number = 6 is bigger than required maximum = 5/.test(errors.age);
errors.color.forEach(function(msg, index,arr){
assert(/string = green is not reference to (.*)/.test(errors.color[index]), "Incorrect message was returned = " + errors.color[index] );
})

validation = /number = 6 is bigger than required maximum = 5/.test(errors.color);

}

},
'Number': {
topic:function(common){
return _.defaults({
Expand Down

0 comments on commit 3eca0db

Please sign in to comment.