Skip to content

[Bug]: Unable to use jest.mock #3206

@badsyntax

Description

@badsyntax

Version

27.1.2

Steps to reproduce

  1. Clone this repo
  2. cd examples/ts-only
  3. npm i
  4. Add jest.mock('example'); to src/welcome-message.spec.ts
  5. Run npm run test-esm

Expected behavior

Jest to run without an error and for the jest mocking to work correctly.

Actual behavior

I get the following error: ReferenceError: jest is not defined

Debug log

I can't post a debug log because GitHub Issues throws an error with There was an error creating your Issue: body is too long (maximum is 65536 characters).

Additional context

I've tried importing jest from @jest/globals which resolved the error but then the mocking does not work.

It would be useful if you could provide a working mocking example.

Environment

System:
    OS: macOS 11.6
    CPU: (8) arm64 Apple M1
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    npm: 8.3.0 - ~/.nvm/versions/node/v16.13.1/bin/npm
  npmPackages:
    jest: ^27.3.1 => 27.4.3 

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions