Function suite

  • Construct a test suite for a validator

    Type Parameters

    • T

      The validated type

    Parameters

    • validator: Validator<T>

      The validator to test

    • valid: {
          input: unknown;
          parsed: T;
      }[]

      An array of valid raw and parsed inputs

    • invalid: Record<string, unknown[]>

      A mapping of validation errors and invalid inputs

    • name: string = validator.name

      The name of the validator to test

    Returns void

    Example

    suite(
    isStringArray,
    [
    { input: [], parsed: [] },
    { input: ["a"], parsed: ["a"] },
    ],
    {
    "Not an array": [undefined, null, true, 1, "a", {}],
    "Not an array of strings": [[1]],
    },
    );