• Equivalent to calling vitest.expect(arg).toBeDefined() while also asserting arg to be defined.

    Type Parameters

    • T

      The type of arg.

    Parameters

    • arg: T

      The variable to be asserted.

    Returns asserts arg is Exclude<T, undefined>

    undefined.

    arg is not undefined.

    const iAmDefined: number | undefined = Math.random() < 1 ? 10 : undefined;
    expectToBeDefined(iAmDefined);
    expect(iAmDefined + 1).toBe(11);