• Equivalent to calling vitest.expect(arg).toBe(expected) while also asserting arg to be the type of expected.

    Type Parameters

    • T

      The type of arg.

    Parameters

    • arg: unknown

      The variable to be asserted.

    • expected: T

      The expected value.

    Returns asserts arg is T

    undefined.

    arg is T.

    const iAmTen: number | null = Math.random() >= 0 ? 10 : Math.random();
    expectToBe(iAmTen, 10);
    // iAmTen is of type 10.
    const inputs = [10, 100] as const;
    const expectedResults = [10, 100] as const;
    inputs.forEach((input, index) => {
    const result = Math.random() >= 0 ? input : Math.random();
    expectToBe(result, expectedResults[index]);
    // result is of type 10 | 100.
    });