-
Notifications
You must be signed in to change notification settings - Fork 237
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
Prefer jest.MockedFunction<T> over jest.Mock #721
Comments
I'd be more ok with it if the type was coming from Jest itself. Will pass on this one, won't pursue it, won't block it. |
Definitely. That's still some time out (unless someone else wants to pursue it), so might be worth doing something else in the meantime? Not sure |
This would be the first typescript-eslint rule wouldn't it? I suppose it would need some other infra, a new preset to opt into or something? |
Don't think so, it'd just look for some other nodes - if they're not there the rule does essentially nothing? |
I guess in this case yeah, but some other TS-related rules may only be a good idea to activate when actually using TS, e.g. some sort of "force X to have a type declared", hence perhaps a ESLint-plugin/preset-jest-typescript may make sense |
I've thought about this in the past - I'm not against TS-related rules, but I couldn't come up with any that actually overlapped with Doing suggestions on types from The math was around the range of types we could actually make recommendations for (as most of the types in |
Going to close this due to lack of activity |
I would like to have such a rule as it might help against problems like the one described here: https://www.salto.io/blog-posts/typescript-unit-testing-pitfalls-with-jest-and-how-to-work-around-them#toc-type-safety-for-mocks |
Since Jest now ships its own types, I think adding this rule is fine. It should target types from |
Would you be able to provide a PR @chtpl? |
The article is talking about Other difference is that The difference between
What might be useful is a rule forcing to pass an argument to all of the utility types. So that the resulting type wouldn’t be based on
Most of the helper types were recently added. The issue is from the times when I was helping to add and polish these helper types to Jest repo (or |
@mrazauskas Thanks for the clarification. As I my journy in the JS/TS ecosystem just started, I don't understand what the difference between types/jest and jest/globals is and when I should use which of these two packages |
See https://jestjs.io/docs/getting-started#type-definitions For a new project I would go for |
OK that clears it up a bit - so types/jest is a bit less verbose because I do not need to import describe, it, expect etc. |
Importing from The |
In typescript
is less ideal then
As the latter forces us to implement the mock correctly (have the right types), would a lint rule enforcing this behavior fall under the scope of this plugin?
The text was updated successfully, but these errors were encountered: