I have a worker_thread
like this:
const worker = new Worker(path.resolve(__dirname, "worker.mjs"))
.on("message", (data) => {
this.date = data;
});
Inside that worker.mjs
, I run a REST API GET
request, and some other formatting logic on the data retrieved.
and I want to mock it in Jest, I tried:
import path from "path";
import { MyModule } from "./MyModule";
describe("MyModule", () => {
jest.mock(path.resolve(__dirname, "worker.mjs"));
it("1st spec", () => {
expect(1+1).toEqual(2)
});
});
But when I run the test, jest
doesn’t mock the worker, jest
goes inside the worker code and actually executes the API call.
What is missing?