@haraldki/unittesterjs
    Preparing search index...

    Class PromiseStatus<T>

    Wrap this around a Promise with pstatus to inspect its state, in particular also to see whether its pending. This object itself is not promise-like. If the wrapped promise needs to be then'ed or awaited for just do so. Example.

     const ps = pstatus(getPending());
    assert.equal(ps.getState(), "pending");
    somehowReject(ps.p, new BoboError());
    await ps.settle();
    assert.isInstance(ps.thrown(), BoboError);

    Type Parameters

    • T
    Index

    Properties

    p: Promise<T>

    The wrapped promise.

    Methods

    • The state of the wrapped promise.

      Returns PromiseState

    • If the wrapped promise was rejected, the rejection value.

      Returns unknown

      whatever the promise was rejected with.

      Error if the promise is not in state rejected.

    • If the wrapped promise was resolved, returns its value.

      Returns T

      the resolved value of the wrapped promise.

      Error if the promise is not in state resolved.

    • The returned promise gets fulfilled as soon as the wrapped promise is settled. Use as

        await ps.settle();
      

      Afterwards, one of getValue or getThrown has a value.

      Returns Promise<void>

    • Creates and returns a PromiseStatus (see for an example) after awaiting a helper Promise to allow for the given p to propagate its state to the PromiseStatus in case it is already settled.

      Type Parameters

      • T

      Parameters

      • p: Promise<T>

      Returns Promise<PromiseStatus<T>>