Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TestRunner

TestRunner makes it easy to write unit tests for kpt functions.

Hierarchy

  • TestRunner

Index

Constructors

constructor

Methods

assert

  • assert(input?: Configs, expectedOutput?: Configs | "unchanged", expectedErrorType?: new (...args: any[]) => Error, expectedErrorMessage?: string | RegExp): Promise<void>
  • Runs the KptFunc and asserts the expected output or error.

    Example usage:

    const RUNNER = new TestRunner(myFunc);

    it('function is a NO OP', async () => {
    await RUNNER.assert());
    };

    Parameters

    • input: Configs = ...

      input Configs passed to the function. It is deep-copied before running the function. If undefined, assumes an empty Configs.

    • Optional expectedOutput: Configs | "unchanged"

      expected resultant Configs after running the function regardless of success or failure. Use 'unchanged' if the function is not expected to change input Configs.

    • Optional expectedErrorType: new (...args: any[]) => Error

      expected error type to be thrown.

        • new (...args: any[]): Error
        • Parameters

          • Rest ...args: any[]

          Returns Error

    • Optional expectedErrorMessage: string | RegExp

      expected message of expection to be thrown.

    Returns Promise<void>

assertCallback

  • assertCallback(input?: Configs, expectedOutput?: Configs | "unchanged", expectedErrorType?: new (...args: any[]) => Error, expectedErrorMessage?: string | RegExp): () => Promise<void>
  • Similar to assert method, but instead returns an assertion function that can be passed directly to 'it'.

    Example usage:

    const RUNNER = new TestRunner(myFunc);

    it('function is a NO OP', RUNNER.assertCallback());

    Parameters

    • input: Configs = ...

      input Configs passed to the function. It is deep-copied before running the function. If undefined, assumes an empty Configs.

    • Optional expectedOutput: Configs | "unchanged"

      expected resultant Configs after running the function regardless of success or failure. Use 'unchanged' if the function is not expected to change input Configs.

    • Optional expectedErrorType: new (...args: any[]) => Error

      expected error type to be thrown.

        • new (...args: any[]): Error
        • Parameters

          • Rest ...args: any[]

          Returns Error

    • Optional expectedErrorMessage: string | RegExp

      expected message of expection to be thrown.

    Returns () => Promise<void>

      • (): Promise<void>
      • Similar to assert method, but instead returns an assertion function that can be passed directly to 'it'.

        Example usage:

        const RUNNER = new TestRunner(myFunc);

        it('function is a NO OP', RUNNER.assertCallback());

        Returns Promise<void>

Generated using TypeDoc