fix: vars starting with 'mock' in hoisted context#3400
fix: vars starting with 'mock' in hoisted context#3400smbkr wants to merge 1 commit intokulshekhar:mainfrom
Conversation
|
Opening this as a draft as I'd like to help here, but unsure how to proceed. So far, I've written a failing e2e test to demonstrate this bug. Initially I started looking at |
|
The unit test data was wrong for Also e2e test data we reuse the same test data Jest has to keep consistency. If you update e2e test, you should take from this https://github.com/facebook/jest/blob/main/e2e/babel-plugin-jest-hoist/__tests__/integration.test.js if I’m not wrong in e2e we have copy 1-1 from jest for test data. |
|
There is one solution I can think of is: including the variables starting with ts-jest/src/transformers/hoist-jest.ts Line 86 in 45a3914 If we do that way, we can ensure those variables will be always above
However, if those constants come from
|
|
Thanks @ahnpnl, I'm planning to continue looking at this when time permits |
|



Summary
This PR attempts to address #3292, where variable whose name starts with
mockcannot be used in a hoisted mock context.In plain jest and jest+babel, one can reference a variable that is not yet initialised when creating a mock which jest will hoist by starting the name with
mock, e.g.mockMyFoo. Presently this throws aReferenceErrorwhen using ts-jest.Test plan
So far I've added an e2e test that demonstrates this bug.
Does this PR introduce a breaking change?
Other information