The flexible lightweight testing library.
It allows for quick simple validations as well as complex nested validation.
Collections, objects and more are supported out of the box and it can be easily extended!
- Chainable tests that read clearly.
- Composable tests that make sense.
- Schema validation for complex objects and arrays.
- An error message structure that is terse and friendly for developers.
npm install the
var the = ;var schema = objectusername: length5 30password:phoneNumbers:;var doc =username: 'Hello'password: 'World'phoneNumbers:'123''555-555-5555';schema; // Throw an error unless doc matches the schema.
The above schema defines the following constraints:
- A required string.
- Must contain only alpha numeric characters.
- Between 5 and 30 characters long.
- An optional string.
- Must satisfy custom regex.
- Must be an array.
- Each element must be a string and a phone number.
"name": "ValidationError""message": "Validation Failed""errors":// The key is the full path of the error. In this case, the first phone number.'phoneNumbers.0':// Array of errors for this path.// The name of the failed validator.type: 'phone'// The value that was at the path (that failed).value: '123'
npm testto run tests.
Please feel free to recommend more default tests and/or submit a PR!