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
I'm trying to setup ts-jest for ESM testing. While working through other jest weirdness, I found that setting their "cache" option to false prevents @jest/globals from being resolved.
The zipped package minimally demonstrates this. Jest config is inline in package.json.
The test should succeed regardless of the cache setting.
Actual behavior
npm run test produces:
FAIL __tests__/cache.spec.ts
● Test suite failed to run
__tests__/cache.spec.ts:1:20 - error TS2792: Cannot find module '@jest/globals'. Did you mean to set the 'moduleResolution' option to 'nodenext
', or to add aliases to the 'paths' option?
Debug log
None was produced.
Additional context
I realize that this is a jest option, but it doesn't have this effect in a .js test.
Did a bit more testing on my end and it seems to be an issue related to import v. require;
If I require the globals the tests consistently pass without the afore mentioned error even when jest's cache option is set to false. The draw back is that type information is lost:
// typed as anyconst{ describe, test, expect }=require('@jest/globals');// ...tests ...
If I use import I get the error the first time, but subsequent runs do not:
Version
29.1.1
Steps to reproduce
I'm trying to setup ts-jest for ESM testing. While working through other jest weirdness, I found that setting their "cache" option to false prevents
@jest/globals
from being resolved.The zipped package minimally demonstrates this. Jest config is inline in package.json.
ts-jest-cache.zip
Expected behavior
The test should succeed regardless of the cache setting.
Actual behavior
npm run test
produces:Debug log
None was produced.
Additional context
I realize that this is a jest option, but it doesn't have this effect in a .js test.
Environment
The text was updated successfully, but these errors were encountered: