Skip to content

Instantly share code, notes, and snippets.

@watert
Created November 21, 2014 16:05
Show Gist options
  • Save watert/610e5bdfed8036c8dcc2 to your computer and use it in GitHub Desktop.
Save watert/610e5bdfed8036c8dcc2 to your computer and use it in GitHub Desktop.
mocha.tv4.base.coffee
{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