Skip to content

jest.mock doesn't modify the type of the mocked class #576

@johngrogg

Description

@johngrogg
  • Issue

The documentation says:

Supports automatic of jest.mock() calls

However, when it is used, the auto-mocked class' type signature isn't updated with the jest mock extensions, which results in errors like:

error TS2339: Property 'mockClear' does not exist on type 'typeof TokenRepository'.

The only "simple" work around I've found is to typecast the mocked class as a jest.Mock like:

(TokenRepository as jest.Mock<TokenRepository>).mockClear();
  • Expected behavior

Ideally provide some way to update the type definitions of auto-mocked classes.

If that's not possible, then at least update the documentation to call out this limitation and provide samples of how to work around it.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions