jest icon indicating copy to clipboard operation
jest copied to clipboard

[BUG] ReferenceError: jest is not defined

Open Lydanne opened this issue 2 years ago • 3 comments

image

Lydanne avatar Jun 11 '22 10:06 Lydanne

You might find importing:

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

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

ThisIsMissEm avatar Jul 14 '22 22:07 ThisIsMissEm

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

abjrcode avatar Mar 16 '23 13:03 abjrcode