You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
jest-compat: jest.mock through a helper's parameter is handled differently for jest and a renamed jest #844
jestMockTransform() treats a helper's parameter differently depending on its name. Once #843 lands:
functionsetup(jest){jest.mock('./a');}// rewritten to vi.doMock('./a'), registeredfunctionsetup(mockJest){mockJest.mock('./a');}// left as is (the parameter shadows the import)
Without the rewrite, the call runs at run time on the jest object, which is Vitest's vi.mock. That call does not reach the Node-side registry (__vnJestMock) and does not apply Jest's factory interop. A later require('./a'), or a Node-owned package, can then load the real module, where Jest would return the mock. The jest case has always been rewritten, and #843 keeps it that way to avoid a behaviour change in a fix release.
Possible direction: treat a call through any parameter or local that is called with the jest object as non-hoisted (doMock/doUnmock semantics, registered), or fail with JEST_BINDING_NOT_FOLLOWED. Either way, a parameter named jest and one named mockJest should give the same result. The runtime consequence should be confirmed with a native test before choosing.
Activity