feat(jest-globals): add Mocked*
utility types to jest
namespace / object
#12425
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
From #12424 (comment)
Currently
jest
object exported from@jest/globals
is missing utility types likejest.MockedClass
,jest.MockedFunction
, which are available from@types/jest
.jest-mock
already has these types, so let’s try to fix this.Obstacles:
declare namespace jest {
is necessary to make this work, butapi-extractor
is throwing away. Right now I was trying to avoid building@jest/globals
, but it should be enough to disable bundling for it. There is just nothing to bundle. (Same with@jest/expect
, by the way!)Currently
jest-mock
has these utility types:Mocked
,MockedClass
,MockedFunction
,MockedObject
and I pulled one more from@types/jest
–SpiedFunction
. Have to write type test to figure out what they all do and if there is no overlap.(Another obvious overlap is
jest.mocked()
function. I am not a big fan of it, to be honest (; That’s another topic. Perhaps it is enough to focus on utility types first.)Test plan
The usual: more type tests and green CI.