Tom Mrazauskas
Tom Mrazauskas
Ah.. The are different solution, but perhaps it would be the best to `require()` CJS modules: ```diff + import { createRequire } from "node:module"; import { jest } from "@jest/globals";...
@iamWing Good idea. I think it would be great to add an example with `jest.unstable_mockModule()` (see https://github.com/facebook/jest/issues/10025#issuecomment-1016690087) and your case with `electron` to ECMAScript Modules guide. Perhaps a link from...
@mildmojo Did you try like this: ```diff - import { createRequire } from "node:module"; import { jest } from "@jest/globals"; - const require = createRequire(import.meta.url); - jest.mock("node:child_process"); + jest.unstable_mockModule("node:child_process", ()...
Agreed (; Are you up to opening a PR?
@anschm Could you provide a repo with minimal reproduction, please? It helps to better understand the problem.
Quick idea. See note at the end of [`moduleNameMapper` option documentation](https://jestjs.io/docs/configuration#modulenamemapper-objectstring-string--arraystring). Feels like this could solve. Does it?
Hm.. Seems like this is just another issue with `@types/jest`. TS complains about the type of `jest.clearAllTimers()` which is: https://github.com/facebook/jest/blob/05cd93bc0bfdd91e2e0b42e51b569ba9f073801f/packages/jest-fake-timers/src/legacyFakeTimers.ts#L119 And here: https://github.com/facebook/jest/blob/05cd93bc0bfdd91e2e0b42e51b569ba9f073801f/packages/jest-environment/src/index.ts#L87 But in `@types/jest` the [return type](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/72c1299e1ad143a84b900f7435c8b9f5f04a1d3e/types/jest/index.d.ts#L159) is...
Trying my luck with https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62204
There is more https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62206 (got merged 🚀)
Thanks! I looked though quickly lots of interesting and useful details. For instance, it would be nice if `jest.requireActual()` would take a type arg. In my todo list, will come...