Skip to content
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

Replace usage of Jest globals with @jest/globals package #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

macko911
Copy link

@macko911 macko911 commented May 19, 2023

Attempts to fix #116

Removed @types/jest package.

Added @jest/globals as peer dependency. I'm not sure about which versions to support, but Jest 28 introduced a breaking change in jest.Mock type definition so I'm not confident how it would work with earlier versions.

Note that this definition is different between @types/jest@29 and @jest/globals@29

The change is described in jestjs/jest#12479
tl;dr the generic type is changed from jest.fn<ReturnType<MyFunctionType>, Parameters<MyFunctionType>> to jest.fn<MyFunctionType>

I did my best to fix the new type errors in the library but I had to add a couple of // @ts-expect-error comments in the process.
The new types work across internal tests and when used as a dependency in our own repo but I'm not sure if they are valid for every existing use case for this library.

Copy link
Contributor

@skovhus skovhus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! 👏

@zavarka
Copy link

zavarka commented Nov 28, 2023

Hi, @skovhus. Thanks for reviewing this merge request. Can you please merge it? I'm hitting this issue too and would love to get this fix. Thank you.

And thank you, @macko911, for putting it together!

@skovhus
Copy link
Contributor

skovhus commented Nov 28, 2023

Hi, @skovhus. Thanks for reviewing this merge request. Can you please merge it? I'm hitting this issue too and would love to get this fix. Thank you.

I would love to, but I'm not a maintainer of jest-mock-extended. ;)

FYI @marchaos

@leighman
Copy link

I think this would also help with bun compatibility since it rewrites references to @jest/globals ?
It doesn't seem to work currently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Doesn't work if injectGlobals is false
4 participants