Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add boolean type-casting

  • Loading branch information...
commit 5105887b13d913aec3024fa8b459bee3e9547699 1 parent df6a8b5
@ixti ixti authored
Showing with 44 additions and 16 deletions.
  1. +44 −16 test/validator-test.js
View
60 test/validator-test.js
@@ -344,28 +344,56 @@ vows.describe('revalidator', {
"with <cast> option": {
topic: {
properties: {
- question: { type: "string" },
- answer: { type: "integer" }
+ answer: { type: "integer" },
+ is_ready: { type: "boolean" }
}
},
- "when the property is castable": {
- topic: function (schema) {
- return revalidator.validate({ answer: "42" }, schema, { cast: true });
+ "and <integer> property": {
+ "when castable": {
+ topic: function (schema) {
+ return revalidator.validate({ answer: "42" }, schema, { cast: true });
+ },
+ "return an object with `valid` set to true": assertValid
},
- "return an object with `valid` set to true": assertValid
+ "when uncastable": {
+ topic: function (schema) {
+ return revalidator.validate({ answer: "forty2" }, schema, { cast: true });
+ },
+ "return an object with `valid` set to false": assertInvalid
+ }
},
- "when the property is uncastable": {
- topic: function (schema) {
- return revalidator.validate({ answer: "forty2" }, schema, { cast: true });
+ "and <boolean> property": {
+ "when castable as 'true/false' string": {
+ topic: function (schema) {
+ return revalidator.validate({ is_ready: "true" }, schema, { cast: true });
+ },
+ "return an object with `valid` set to true": assertValid
},
- "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 });
+ "when castable as '1/0' string": {
+ topic: function (schema) {
+ return revalidator.validate({ is_ready: "1" }, schema, { cast: true });
+ },
+ "return an object with `valid` set to true": assertValid
},
- "return an object with `valid` set to true": assertValid
+ "when castable as `1/0` integer": {
+ topic: function (schema) {
+ return revalidator.validate({ is_ready: 1 }, schema, { cast: true });
+ },
+ "return an object with `valid` set to true": assertValid
+ },
+ "when uncastable as string": {
+ topic: function (schema) {
+ return revalidator.validate({ is_ready: "not yet" }, schema, { cast: true });
+ },
+ "return an object with `valid` set to false": assertInvalid
+ },
+ "when uncastable as number": {
+ topic: function (schema) {
+ return revalidator.validate({ is_ready: 42 }, schema, { cast: true });
+ },
+ "return an object with `valid` set to false": assertInvalid
+ }
}
- },
+ }
}
}).export(module);
Please sign in to comment.
Something went wrong with that request. Please try again.