Created
November 21, 2014 16:05
-
-
Save watert/610e5bdfed8036c8dcc2 to your computer and use it in GitHub Desktop.
mocha.tv4.base.coffee
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
{assert} = chai | |
do -> | |
parseSchema = (schema)-> | |
if schema?.properties | |
_schema = schema | |
else | |
properties = schema | |
_schema = | |
"type": "object" | |
"properties":schema | |
# for k,v of _schema.properties | |
# if typeof v is "string" | |
# _schema.properties[k] = type:v | |
return _schema | |
assert.valid = (data,schema)-> | |
_schema = parseSchema(schema) | |
result = tv4.validateResult(data,_schema) | |
if result.error then console.error "Valid Error:",result | |
assert(result.valid,"#{result.error?.dataPath} :: #{result.error}") | |
assert.notValid = (data,schema)-> | |
_schema = parseSchema(schema) | |
result = tv4.validateResult(data,_schema) | |
assert.notOk(result.valid,"schema is valid when needs it to be invalid") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment