Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ImperativeExpect

Helper class for paramter validation. Expectations that fail will throw an ImperativeError with a validation error message.

All methods allow keys to be specified as "property1.prop.lastprop" for example.

export

Hierarchy

  • ImperativeExpect

Index

Properties

Static Readonly ERROR_TAG

ERROR_TAG: string = "Expect Error"

The error tag to append to each error message.

static
memberof

ImperativeExpect

Methods

Static arrayToContain

  • arrayToContain(arr: any[], compare: (entry: any) => boolean, msg?: string): any
  • Expect the object passed to be an array that contains a particular entry. Your compare method is invoked to determine if the entry you're looking for is found within the array.

    static
    memberof

    ImperativeExpect

    Parameters

    • arr: any[]

      the array to search

    • compare: (entry: any) => boolean

      compare method (passed the parms) - return true if the entry is found within the array.

        • (entry: any): boolean
        • Parameters

          • entry: any

          Returns boolean

    • Optional msg: string

    Returns any

    • If a match is found, it will return the match.

Static expectAndTransform

  • expectAndTransform(expect: () => void, transform: (error: any) => ImperativeError): void
  • Expect a situation and transform the error (if expect fails). Accepts two methods of your implementation to: A) Test the expect (which is intended to throw an ImperativeError) B) Transform and return a new ImperativeError This allows you complete control over the contents of the error. If you are only interested in influencing the message displayed, then use the msg parm on each of the expect functions.

    static
    memberof

    ImperativeExpect

    Parameters

    • expect: () => void

      The method that contains your ImperativeExpect invocation

        • (): void
        • Returns void

    • transform: (error: any) => ImperativeError

      Passed the error thrown by the expect and expects you to return the ImperativeError you would like thrown.

    Returns void

Static keysToBeAnArray

  • keysToBeAnArray(obj: {} | any, nonZeroLength: boolean, keys: string[], msg?: string): void
  • Expect a set of keys (by name) to be defined, of type array, and optionally a non-zero length array.

    static

    Parameters

    • obj: {} | any

      the object for which you would like to assert that certain fields

    • nonZeroLength: boolean

      if true, the length of the array must be non zero

    • keys: string[]

      keys in object that should be arrays

    • Optional msg: string

    Returns void

Static keysToBeDefined

  • keysToBeDefined(obj: {} | any, keys: string[], msg?: string): void

Static keysToBeDefinedAndNonBlank

  • keysToBeDefinedAndNonBlank(obj: {} | any, keys: string[], msg?: string): void
  • Expect that a set of keys are defined, of type string, and are non-blank (after trimming).

    static
    memberof

    ImperativeExpect

    Parameters

    • obj: {} | any

      object to test existence

    • keys: string[]

      keys in object

    • Optional msg: string

    Returns void

Static keysToBeOfType

  • keysToBeOfType(obj: {} | any, type: string, keys: string[], msg?: string): void
  • Expect a set of keys to be of a certain type.

    static
    memberof

    ImperativeExpect

    Parameters

    • obj: {} | any

      The input object

    • type: string

      The type to check for (only primatives - uses "typeof")

    • keys: string[]

      A list of keys to check in the object

    • Optional msg: string

    Returns void

Static keysToBeUndefined

  • keysToBeUndefined(obj: {}, keys: string[], msg?: string): void

Static toBeAnArray

  • toBeAnArray(arr: any[], msg?: string): void

Static toBeDefinedAndNonBlank

  • toBeDefinedAndNonBlank(item: string, label: string, msg?: string): void

Static toBeEqual

  • toBeEqual(value1: any, value2: any, msg?: string): void

Static toBeOneOf

  • toBeOneOf(value: any, arr: any[], msg?: string): any
  • Check if the input is one of several possibilities in a list.

    static
    memberof

    ImperativeExpect

    Parameters

    • value: any

      The value to find in following array

    • arr: any[]

      The array of possible items we could be expecting

    • Optional msg: string

    Returns any

    • If a match is found, it will return the match.

Static toMatchRegExp

  • toMatchRegExp(value: any, myRegex: string, msg?: string): void
  • Expect that value matches the regular expression (via ".test()" method).

    static
    memberof

    ImperativeExpect

    Parameters

    • value: any

      Value

    • myRegex: string

      Regular expression

    • Optional msg: string

    Returns void

Static toNotBeEqual

  • toNotBeEqual(value1: any, value2: any, msg?: string): void

Static toNotBeNullOrUndefined

  • toNotBeNullOrUndefined(obj: any, msg?: string): void

Generated using TypeDoc