Options
All
  • Public
  • Public/Protected
  • All
Menu

Module promise_utils

Index

Functions

catchLater

  • catchLater(promise: Promise<any>): Promise<any>
  • Avoid UnhandledPromiseRejectionWarning if a promise fails before we await it.

    example
    const emailPromise = catchLater(getMail(...));
    await ...
    const email = await emailPromise;
    

    Parameters

    • promise: Promise<any>

      A promise to ignore for now (will be caught later)

    Returns Promise<any>

customErrorMessage

  • customErrorMessage(promise: Promise<any>, message: string): Promise<any>
  • Attach a custom error message if a promise fails. If the promise succeeds, this function does nothing.

    example
    const page = newPage(config);
    await page.goto('https://example.org/');
    await customErrorMessage(
        page.waitForSelector('blink'), '<blink> element not found (BUG-123)');
    await closePage(page);
    

    Parameters

    • promise: Promise<any>

      The promise to wait for.

    • message: string

      Custom message to attach to the error;

    Returns Promise<any>

expectedToFail

  • expectedToFail(config: any, message: string, asyncFunc: () => any, __namedParameters?: {}): Promise<void>
  • Mark a code section as expected to fail. If the async function throws an error, the error will be included in reports, but not counted as a test failure. If the async function succeeds, a warning will be printed.

    example
    await expectedToFail(config, 'BUG-1234', async() => {
        ...
    }, {
        expectNothing: config.env === 'very-good-environment',
    });
    

    Parameters

    • config: any

      The pentf configuration.

    • message: string

      Error message to show when the section fails (recommended: ticket URL)

    • asyncFunc: () => any

      The asynchronous section which is part of the test.

        • (): any
        • Returns any

    • __namedParameters: {} = {}

      Options (currently not visible in output due to typedoc bug)

    Returns Promise<void>

timeoutPromise

  • timeoutPromise(config: any, promise: Promise<any>, __namedParameters?: {}): any
  • Raise an error if a promise does not finish within a certain timeframe. Note this does not cancel the promise itself (because that's impossible).

    Parameters

    • config: any

      The pentf configuration.

    • promise: Promise<any>

      The promise to limit

    • __namedParameters: {} = {}

      Options (currently not visible in output due to typedoc bug)

    Returns any

    Whatever the promise returned, if it is successful

Generated using TypeDoc