The variable to be asserted.
The expected value.
undefined
.
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"; }
});
Equivalent to calling
vitest.expect(arg).toEqual(expected)
while also assertingarg
to be the type ofexpected
.