# jest/no-untyped-mock-factory

> Require a type parameter on `jest.mock()` and `jest.doMock()` with a factory

TypeScript doesn't compare the object a `jest.mock()` factory returns with the module it replaces. If you rename an export or change its arguments, the mock keeps the old shape and the test still compiles. With a type parameter, `jest.mock<typeof import("./mailer")>(..)`, the factory must return what the module exports.

The rule only runs in TypeScript files. A factory with a return type is accepted too.

`--fix` adds `<typeof import('..')>` if the module name is a string literal.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"jest/no-untyped-mock-factory" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```ts
import { jest } from "@jest/globals";

jest.mock("./mailer", () => ({
  send: jest.fn(),
}));
```

Not reported:

{/* good */}
```ts
import { jest } from "@jest/globals";

jest.mock<typeof import("./mailer")>("./mailer", () => ({
  send: jest.fn(),
}));

jest.doMock("./clock", (): typeof import("./clock") => ({
  now: () => 0,
}));

jest.mock("./database");
```
