Equivalent to calling vitest.expect(arg).toBe(expected) while also asserting arg to be the type of expected.
vitest.expect(arg).toBe(expected)
arg
expected
The type of arg.
The variable to be asserted.
The expected value.
undefined.
undefined
arg is T.
T
const iAmTen: number | null = Math.random() >= 0 ? 10 : Math.random();expectToBe(iAmTen, 10);// iAmTen is of type 10. Copy
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.}); Copy
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.});
Equivalent to calling
vitest.expect(arg).toBe(expected)
while also assertingarg
to be the type ofexpected
.