Options
All
  • Public
  • Public/Protected
  • All
Menu

Module assert_utils

Index

Functions

assertAlways

  • assertAlways(testfunc: () => any, __namedParameters?: undefined | { checkEvery: undefined | number; message: undefined | string; timeout: undefined | number }): Promise<void>
  • Assert that a condition remains true for the whole timeout.

    Parameters

    • testfunc: () => any

      The test function. Must return true to signal success.

        • (): any
        • Returns any

    • __namedParameters: undefined | { checkEvery: undefined | number; message: undefined | string; timeout: undefined | number } = {}

    Returns Promise<void>

assertAsyncEventually

  • assertAsyncEventually(testfunc: () => Promise<any>, __namedParameters?: undefined | {}): Promise<any>
  • Assert that an asynchronously evaluated condition is eventually true.

    Parameters

    • testfunc: () => Promise<any>

      The async test function. Must return true to signal success.

        • (): Promise<any>
        • Returns Promise<any>

    • __namedParameters: undefined | {} = {}

    Returns Promise<any>

assertEventually

  • assertEventually(testfunc: () => any, __namedParameters?: undefined | {}): Promise<any>
  • Assert that a condition is eventually true.

    example
    let called = false;
    setTimeout(() => {called = true;}, 2000);
    await assertEventually(() => called);
    

    Parameters

    • testfunc: () => any

      The test function. Must return true to signal success.

        • (): any
        • Returns any

    • __namedParameters: undefined | {} = {}

    Returns Promise<any>

assertGreater

  • assertGreater(x: number | BigInt, y: number | BigInt, message?: null | string): void
  • Assert x < y.

    Parameters

    • x: number | BigInt

      The ostensibly larger value.

    • y: number | BigInt

      The ostensibly smaller value.

    • message: null | string = ...

      Optional error message if the assertion does not hold.

    Returns void

assertGreaterEqual

  • assertGreaterEqual(x: number | BigInt, y: number | BigInt, message?: null | string): void
  • Assert x >= y.

    Parameters

    • x: number | BigInt

      The ostensibly smaller or equal value.

    • y: number | BigInt

      The ostensibly larger or equal value.

    • message: null | string = ...

      Optional error message if the assertion does not hold.

    Returns void

assertHttpStatus

  • assertHttpStatus(response: any, expectedStatus?: null | number, __namedParameters?: undefined | {}): any
  • Assert that an HTTP response finished with the given status code.

    example
    const response = await fetch(config, 'https://foo.example/');
    await assertHttpStatus(response, 200);
    // Or, the shorter form:
    const shortResponse = await assertHttpStatus(fetch(config, 'https://foo.example/'));
    

    Parameters

    • response: any

      HTTP fetch response object, as gotten from await [["net_utils".fetch|netutils.fetch]](...), or the promise resolving to that (e.g. just [["net_utils".fetch|netutils.fetch]](...)`).

    • expectedStatus: null | number = 200

      The expected HTTP status (e.g. 201 for Created)

    • __namedParameters: undefined | {} = {}

    Returns any

    The fetch response object.

assertIncludes

  • assertIncludes(haystack: any, needle: any, message?: null | string): void
  • Assert that a string is included in another, or object is included in an array.

    example
    assertIncludes('foobar', 'foo');
    assertIncludes([9, 5, 3], 5);
    

    Parameters

    • haystack: any

      The thing to search in.

    • needle: any

      The thing to search for.

    • message: null | string = ...

      Optional error message if the assertion does not hold.

    Returns void

assertLess

  • assertLess(x: number | BigInt, y: number | BigInt, message?: null | string): void
  • Assert x < y.

    Parameters

    • x: number | BigInt

      The ostensibly smaller value.

    • y: number | BigInt

      The ostensibly larger value.

    • message: null | string = ...

      Optional error message if the assertion does not hold.

    Returns void

assertLessEqual

  • assertLessEqual(x: number | BigInt, y: number | BigInt, message?: null | string): void
  • Assert x <= y.

    Parameters

    • x: number | BigInt

      The ostensibly smaller or equal value.

    • y: number | BigInt

      The ostensibly larger or equal value.

    • message: null | string = ...

      Optional error message if the assertion does not hold.

    Returns void

assertNotIncludes

  • assertNotIncludes<T>(haystack: T[], needle: T, message?: null | string): void
  • Assert that a string is not included in another, or object is not included in an array.

    example
    assertNotIncludes('foobar', 'xxx');
    assertNotIncludes([9, 5, 3], 2);
    

    Type parameters

    • T

    Parameters

    • haystack: T[]

      The thing to search in.

    • needle: T

      The thing to search for.

    • message: null | string = ...

      Optional error message if the assertion does not hold.

    Returns void

assertNumeric

  • assertNumeric(x: number | BigInt, message?: any): void
  • Assert that a value is a Number or BigInt.

    Parameters

    • x: number | BigInt

      The value to check.

    • message: any = ...

    Returns void

lazyAssert

  • lazyAssert(value: boolean, makeMessage: () => string): void
  • Assert function with a message that is generated on demand.

    example
    lazyAssert(obj?.foo?.bar, () => `Object is missing foo.bar. Full object: ${JSON.stringify(obj)}`);
    

    Parameters

    • value: boolean

      The value to be asserted to be true.

    • makeMessage: () => string

      Function to generate the error message, should the value be false.

        • (): string
        • Returns string

    Returns void

waitFor

  • waitFor(testfunc: () => any, options?: undefined | {}): Promise<void>
  • Wait until a function returns a result that is truthy

    Parameters

    • testfunc: () => any
        • (): any
        • Returns any

    • options: undefined | {} = {}

    Returns Promise<void>

waitForPass

  • waitForPass(testfunc: () => any, options?: undefined | {}): Promise<void>
  • Wait until a function doesn't throw anymore.

    Parameters

    • testfunc: () => any
        • (): any
        • Returns any

    • options: undefined | {} = {}

    Returns Promise<void>

Generated using TypeDoc