Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ReferenceError: jest is not defined #104

Open
WumaCoder opened this issue Jun 11, 2022 · 4 comments
Open

[BUG] ReferenceError: jest is not defined #104

WumaCoder opened this issue Jun 11, 2022 · 4 comments

Comments

@WumaCoder
Copy link

image

@ThisIsMissEm
Copy link

You might find importing:

import { jest } from '@jest/globals'`

to help. I suspect something is causing the jest injectGlobals option to not apply.

@abjrcode
Copy link

Same issue here. I am using the following .swcrc and jest configuration:

.swcrc

{
  "$schema": "http://json.schemastore.org/swcrc",
  "jsc": {
    "target": "es2020",
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": true,
      "dynamicImport": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true,
      "hidden": {
        "jest": true
      }
    },
    "externalHelpers": true
  },
  "module": {
    "type": "commonjs",
    "strict": false,
    "strictMode": true,
    "lazy": false,
    "noInterop": false
  }
}

Jest

const config = {
  transform: {
    '^.+\\.tsx?$': ['@swc/jest'],
  },
  testEnvironment: 'node',
  testMatch: ['**/*.test.ts'],
  verbose: false,
  testTimeout: 200,
  testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/build/'],
  modulePathIgnorePatterns: ['<rootDir>/build/'],

  restoreMocks: true,
  clearMocks: true,
  resetMocks: true,
}

export default config

Running a backend project with Node 18 and TypeScript

@erperejildo
Copy link

import { jest } from '@jest/globals'`

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

@kdy1
Copy link
Member

kdy1 commented Jul 4, 2024

Can someone provide a reproduction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants