AkifumiSato / esbuild-jest-transform

14 stars 9 forks source link

Do not import `@jest/globals` outside of the Jest test environment #12

Closed gustawdaniel closed 1 year ago

gustawdaniel commented 1 year ago

I have both cypress and jest in single project. My ide shows autocompletions for expect from

Chai.ExpectStatic. (     val: any,     message?: string): Assertion
  cypress

I was using package esbuild-jest with

import {expect} from '@jest/globals';

to fix problem with autocompletion.

Not this import leads to error when I switched to esbuild-jest-transform. This is error:

▲ [WARNING] Import "expect" will always be undefined because the file "node_modules/@jest/globals/build/index.js" has no exports [import-is-undefined]

    tests/unit/generatePaymentLink.test.ts:3:8:
      3 │ import {expect} from '@jest/globals';
 FAIL  tests/unit/generatePaymentLink.test.ts
  ● Test suite failed to run

    Do not import `@jest/globals` outside of the Jest test environment

but when I remove line import {expect} from '@jest/globals'; then I see problems in Webstorm IDE but tests pass correctly.

gustawdaniel commented 1 year ago

Fixed by switch to jest-esbuild.