-
Notifications
You must be signed in to change notification settings - Fork 455
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
Proposal: partialMocked - mocked, but less strict return/resolved values. #1065
Comments
there is a discussion about mock utils in #1048 . If jest team agrees to migrate mock utils to jest repo, perhaps this proposal can go into jest repo. |
Hi @dylang , I already mentioned this issue in jest feature request. I will close this issue as won’t build. If you still want to have this request, please create a request for jest team. |
Did this |
I'm also running into this issue in a codebase that I've inherited. The OP describes the problem very succinctly. The only workaround that the authors found was to stop using TypeScript with these kinds of files and use JSX instead. |
I have pasted this issue on jestjs/jest#13325. Hopefully, it will be picked up 🥲 |
Issue :
I want to do something like this...
But because
foo
returns a dozen other properties that the test doesn't rely on, so we get errors like this:Workarounds:
This takes away the nice typing
mocked
provides:This isn't always possible, as running the original function can have side effects, or return something that can't be easily merged like a promise, and
jest.requireActual
's return type isany
so it doesn't even solve the original problem.Preferred behavior :
A new function called
partialMocked
(maybe there's a better name?) that allowsreturnType
/resolvedValue
/etc to be a deep partial of what it normally returns.Example implementation :
This fixed the issues I was having. I'm still fairly new with TypeScript, so I'm not sure if this is a complete solution or the right way to do it, so that's why I made this ticket instead of starting with a pull request.
Thoughts?
The text was updated successfully, but these errors were encountered: