Skip to main content
Version: 5.x

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.

  • staticSuite - creates a stateless suite that is used for server side validations.

  • test - A single validation test inside your suite.

    • test.memo - Memoizes a test run as long as its dependencies haven't changed.
    • warn - resides within the test body. Sets the test's severity to warning.
  • 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.
  • isTested - Returns true if the provided field has been tested.
  • 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.

Vest's external exports