-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect types for lifecycle functions #10066
Comments
Happening with me too. It looks like the lifecycle hooks got typed as This would fix it: export interface TestFrameworkGlobals {
it: ItConcurrent;
test: ItConcurrent;
fit: ItBase & {
concurrent?: ItConcurrentBase;
};
xit: ItBase;
xtest: ItBase;
describe: Describe;
xdescribe: DescribeBase;
fdescribe: DescribeBase;
// beforeAll: HookFn; <--- this is wrong, replace with:
beforeAll: (fn: HookFn, timeout?: number) => void;
...
} |
We still don't support generator functions in the types - anybody up for a PR adding it? 🙂 |
Oops, forgot about it. Should the typing of |
I failed to find examples of usage of Generators on hooks and tests. It wasn't clear to me if Help Wanted indeed. Wording on the docs is a bit ambiguous.
Generators are not mentioned in the I'll try to use the |
Just pinging issue subscribers, the PR is ready. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
The types for the lifecycle functions (
beforeEach
etc.) are declared incorrectly inpackages/jest-types/src/Global.ts
. These functions are documented as being able to return a promise or generator and accepting a timeout parameter but the defined types disallow anything except a void returning function.To Reproduce
Take the following code:
This causes TypeScript to complain with
Expected 0-1 arguments, but got 2. ts(2554)
and causes the typescript-eslint rule no-misused-promises to complain withPromise returned in function argument where a void return was expected.
.Expected behavior
The given code should not show any issues.
I think that the type for HookFn should be changed to something like this:
envinfo
The text was updated successfully, but these errors were encountered: