bun icon indicating copy to clipboard operation
bun copied to clipboard

ReferenceError: Can't find variable: jest

Open sibelius opened this issue 2 years ago • 4 comments

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

Try to run any jest test without using @jest/globals

What is the expected behavior?

it should work

What do you see instead?

ReferenceError: Can't find variable: jest

Additional information

try to test against jest-fetch-mock

sibelius avatar Sep 11 '23 11:09 sibelius

For run tests use command: bun test

dhffdh avatar Sep 11 '23 12:09 dhffdh

I'm running using bun test path/to/myjesttest.ts

sibelius avatar Sep 11 '23 12:09 sibelius

I don't think it's expected to polyfill/shim references to jest itself, only the functions expect, test, describe, etc.

tomhicks avatar Sep 11 '23 13:09 tomhicks

do you have a file that reproduces this? I'm happy to investigate this if it is still impacting you

nektro avatar May 24 '24 04:05 nektro

It affects eg. any test that uses jest-mock-extended https://github.com/marchaos/jest-mock-extended/pull/119#issuecomment-1887493808

leighman avatar May 27 '24 12:05 leighman

Having the same issue when running with bun test path/to/myjesttest.ts

bun --version
1.1.9

wnz99 avatar Jul 26 '24 14:07 wnz99

Having the same issue

# Unhandled error between tests
-------------------------------
77 |   }
78 | }
79 |
80 | const isFn = unknown => typeof unknown === 'function'
81 |
82 | const isMocking = jest.fn(staticMatches(true))
                       ^
ReferenceError: Can't find variable: jest
      at ./project/node_modules/jest-fetch-mock/src/index.js:82:19

Bun version 1.1.21

zenofsahil avatar Sep 09 '24 14:09 zenofsahil

I had the same issue, I fixed it by

  1. Installing @types/bun
  2. Importing the test utils from bun: import { describe, test, expect } from "bun:test";

berenar avatar Sep 27 '24 09:09 berenar