API Reference
Below is a list of all the API functions exposed by Vest.
Vest's main export API
create - Creates a new Vest suite. Returns a function that runs your validations.
- suite.get - Returns the current validation state of the suite.
- suite.remove - Removes a single field from the suite.
- suite.reset - Resets the suite to its initial state.
- suite.resetField - Resets a single field to an untested state.
staticSuite - creates a stateless suite that is used for server side validations.
test - A single validation test inside your suite.
enforce - Asserts that a value matches your desired result.
- enforce.extend - Extends the enforce API with your own custom assertions.
- compose - Compose multiple enforcers into a single enforcer.
only - Makes Vest only run the provided field names.
skip - Makes Vest skip the provided field names.
include()/include.when() - Link fields by running them together based on a criteria.
skipWhen - Skips a portion of the suite when the provided condition is met.
omitWhen - Omits a portion of the suite when the provided condition is met.
optional - Allows you to mark a field as optional.
group - Allows grouping multiple tests with a given name.
each - Allows iteration over an array of values to dynamically run tests.
mode - Determines whether Vest should continue running tests after a field has failed, or if it should bail immediately.
- Possible modes are: 'EAGER' (default) and 'ALL'.
Suite Result API
After running your suite, the results object is returned. It has the following functions:
- hasErrors - Returns true if the suite or the provided field has errors.
- hasWarnings - Returns true if the suite or the provided field has warnings.
- getError - Returns the first error in the suite, or of a specific field.
- getWarning - Returns the first warning in the suite, or of a specific field.
- getErrors - Returns an object with errors in the suite, or an array of objects for a specific field.
- getWarnings - Returns an object with warnings in the suite, or an array of objects for a specific field.
- hasErrorsByGroup - Returns true if the provided group has errors.
- hasWarningByGroup - Returns true if the provided group has warnings.
- getErrorsByGroup - Returns an object with errors in the provided group.
- getWarningsByGroup - Returns an object with warnings in the provided group.
- isPending - Returns true if the suite has pending async tests.
- isValid - Returns true if the suite or the provided field is valid.
- isValidByGroup - Returns true if a certain group or a field in a group is valid or not.
- done - Accepts a callback that will run when the suite is done running.