Permalink
Browse files

Add type-casting feature tests

  • Loading branch information...
1 parent c26d194 commit c984bc86f65e947260a8a8625a1e43dbab31103b @ixti ixti committed Aug 7, 2012
Showing with 27 additions and 1 deletion.
  1. +27 −1 test/validator-test.js
View
@@ -315,6 +315,32 @@ vows.describe('revalidator', {
"and an error concerning the 'pattern' attribute": assertHasError('pattern')
},
}
- }
+ },
+ "with <cast> option": {
+ topic: {
+ properties: {
+ question: { type: "string" },
+ answer: { type: "integer" }
+ }
+ },
+ "when the property is castable": {
+ topic: function (schema) {
+ return revalidator.validate({ answer: "42" }, schema, { cast: true });
+ },
+ "return an object with `valid` set to true": assertValid
+ },
+ "when the property is uncastable": {
+ topic: function (schema) {
+ return revalidator.validate({ answer: "forty2" }, schema, { cast: true });
+ },
+ "return an object with `valid` set to false": assertInvalid
+ },
+ "casting should respect property type": {
+ topic: function (schema) {
+ return revalidator.validate({ question: "42" }, schema, { cast: true });
+ },
+ "return an object with `valid` set to true": assertValid
+ }
+ },
}
}).export(module);

0 comments on commit c984bc8

Please sign in to comment.