chai-joi
Extends Chai with Joi specific assertions.
TL;DL
Assuming that result
is the result of a Joi validation:
-
Assert-style
- chai.assert.isValidation(result)
-
BDD-style
- result.should
- [.not].be.a.validation
- [.not].validate
- [.not].have.an.error
- [.not].have.a.value
- [.not].have.errmsgs
- [.not].have.errmsgs.that.include(str)
- [.not].have.errmsg(str)
- result.should
-
TDD-style
- expect(result).to
- [.not].be.a.validation
- [.not].validate
- [.not].have.an.error
- [.not].have.a.value
- [.not].have.errmsgs
- [.not].have.errmsgs.that.include(str)
- [.not].have.errmsg(str)
- expect(result).to
(See test/chai-joi.js for uses.)
Example:
var joi = chai = expect = chaiexpect; chai; chai; var data= str:'foo' num: 100; var schema=joiobject str:joi num:joi; var result=joi; resultshouldnotvalidate;resultshouldhave; datanum=1;result=joi; tovalidate;tonothaveerrmsgs; // same thing, really.
assert
Extension to chai.assert to test for a valid Joi validation result.
assert.isValidation(target)
Asserts that the target object is result of a call to Joi.validate()
Parameters
target: object
, Asserts that the target object is result of a call to Joi.validate()
Returns: boolean
property
Chainable properties.
property.validation()
Assert that target is a Joi validation
Example:
tonotbeavalidationtargetshouldnotbeavalidation
property.validate()
Assert that target validates correctly
Example:
shouldnotvalidatetargetshouldnotvalidate
property.error()
Assert that target contains one or more errors (unsuccessful validation). Mutates current chainable object to be target.error.
Example:
tonothaveanerrortargetshouldnothaveanerror
property.value()
Assert that target contains a value. Mutates current chainable object to be target.value.
Example:
tonothaveavaluetargetshouldnothaveavalue
property.errmsgs()
Assert that target contains one or more error messages (unsuccessful validation). Mutates current chainable object to be list {String[]} of error messages.
Example:
tonothaveerrmsgstargetshouldnothaveerrmsgstonothaveerrmsgsthattargetshouldhaveerrmsgsthat
method
Chainable methods.
method.errmsg(msg)
Assert that target contains specified error message (unsuccessful validation).
Parameters
msg: String
, errmsg to match
Example:
targetshouldnothave