Skip to main content

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.
  • 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.

    • only.group - Makes Vest only run the provided group names.
  • skip - Makes Vest skip the provided field names.

  • include()/include.when() - Link fields by running them together based on a criteria.

    • skip.group - Makes Vest skip the provided group names.
  • 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.

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.
  • 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.
  • isValid - Returns true if the suite or the provided field is valid.
  • done - Accepts a callback that will run when the suite is done running.

Vest's external exports​