You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have noticed that writing a test case which contains a call to a method or function with invalid parameters, does not result in a test failure. Consider the following example using Typescript:
// test.test.ts
import { test, expect, vi } from "vitest";
const function2 = vi.fn((a, b) => {})
const function1 = (param1: number, param2: number) => {
function2(param1, param2);
return "done";
}
test("That calls that don't match signatures are detected.", () => {
const result = function1();
expect(result).toBe("done");
expect(function2).toHaveBeenCalledOnce();
});
In this scenario, function1() requires two parameter of type number that will be sent over to function2(). As its internal logic does directly interact with the parameters, no exceptions are thrown during executor. So both expect are a success and the test case passes.
I understand in plain JS, function1 would receive both parameters as undefined. But this being a TypeScript file, wouldn't the internal test compiler throw an error that result in a test failure?
The error is indeed highlighted is you use an IDE that supports TS checks:
IMO the use of an invalid method signature should not result in a valid test case.
@AriPerkkio I think the argument detection should happen when the TypeScript code gets transpiled to JS. In this scenario, if a .ts file contains any invalid syntax the whole test suit described on that file could be marked as failure.
I agree with you that using toHaveBeenCalledWith and toHaveBeenNthCalledWith can be used for the case of my example. But the issue I mentioned can be reproduced, i.e., while creating a new class instance and not sending the correct parameters to the constructor.
Describe the bug
I have noticed that writing a test case which contains a call to a method or function with invalid parameters, does not result in a test failure. Consider the following example using Typescript:
In this scenario,
function1()
requires two parameter of type number that will be sent over tofunction2()
. As its internal logic does directly interact with the parameters, no exceptions are thrown during executor. So bothexpect
are a success and the test case passes.I understand in plain JS,
function1
would receive both parameters as undefined. But this being a TypeScript file, wouldn't the internal test compiler throw an error that result in a test failure?The error is indeed highlighted is you use an IDE that supports TS checks:
IMO the use of an invalid method signature should not result in a valid test case.
Reproduction
See description above with example.
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: