• Equivalent to calling vitest.expect(arg).toEqual(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 parsed = JSON.parse('{"key": "val"}')
    expectToEqual(parsed, {key: "val"} as const);
    // parsed is of type {readonly key: "val"}.
    const inputs = ['{"key1": "val1"}', '{"key2": "val2"}'];
    const expectedResults = [{ key1: "val1" }, { key2: "val2" }] as const;
    inputs.forEach((input, index) => {
    const parsed = JSON.parse(input);
    expectToEqual(parsed, expectedResults[index]);
    // parsed is of type { readonly key1: "val1"; } | { readonly key2: "val2"; }
    });