Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
216 additions
and
94 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
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,68 @@ | ||
var vows = require('vows') | ||
, assert = require('assert') | ||
, printTestResult = require('../printTestResult.js') | ||
, schema = require('../../index.js') | ||
|
||
|
||
// Create a Test Suite | ||
vows.describe('Validation Object').addBatch({ | ||
'Object': { | ||
"original validate schema has a bug with regexp field validation.": function () { | ||
//object should have at least one String field | ||
var validation = schema({ | ||
"+.+" : String | ||
}); | ||
var emptyObject = {}; | ||
assert(false, validation(emptyObject)); | ||
|
||
var emptyArray = []; | ||
assert(false, validation(emptyArray)); | ||
}, | ||
"some fields are valid, all the rest are not": function () { | ||
var validation = schema({ | ||
"+check.?" : Number, | ||
"*" : null | ||
}); | ||
var correctObject = { | ||
check1 : 1, | ||
check2 : 2 | ||
}; | ||
assert(true, validation(correctObject)); | ||
var incorrectObject = { | ||
check1 : 1, | ||
check2 : 2, | ||
someOther : 3 | ||
}; | ||
assert(false, validation(incorrectObject)); | ||
}, | ||
"with allowed other fields": function () { | ||
var anotherValidation = schema({ | ||
"+check.?": Number, | ||
"*": Number | ||
}); | ||
var o1 = { | ||
check1: 1, | ||
check2: 2 | ||
}; | ||
var o2 = { | ||
check1: 1, | ||
check2: 2, | ||
someOther: 3 | ||
}; | ||
|
||
assert(true, anotherValidation(o1)); | ||
assert(true, anotherValidation(o2)); | ||
}, | ||
"empty object should be valid sometimes": function () { | ||
var allowAll = schema({ | ||
"*": String | ||
}); | ||
assert(true, allowAll({})); | ||
|
||
var allowSome = schema({ | ||
"check": [null, String] | ||
}); | ||
assert(true, allowSome({})); | ||
} | ||
} | ||
}).export(module) |