Skip to content

[Bug]: referencing jest inside jest.mock block throws, if jest is imported from @jest/globals #12422

@mrazauskas

Description

@mrazauskas

Version

28.0.0-alpha.3

Steps to reproduce

Here is a repo with minimal reproduction: https://github.com/mrazauskas/x-jest-globals

I simply added explicit import to the example from docs (and used TS to trigger transpiration) – https://jestjs.io/docs/next/mock-functions#mocking-partials

Running yarn jest will throw an ReferenceError:

Screenshot 2022-02-18 at 09 38 22

Expected behavior

It should not throw ReferenceError.

Actual behavior

It throws ReferenceError, probably because of transpilation. I also tried transpiling using ts-jest and the error was gone. It seems like only users of babel-jest are affected.

Additional context

No response

Environment

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
  Binaries:
    Node: 17.3.1 - ~/.nvm/versions/node/v17.3.1/bin/node
    Yarn: 1.22.15 - ~/.nvm/versions/node/v17.3.1/bin/yarn
    npm: 8.3.0 - ~/.nvm/versions/node/v17.3.1/bin/npm
  npmPackages:
    jest: ^28.0.0-alpha.3 => 28.0.0-alpha.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions