jest
jest copied to clipboard
[BUG] ReferenceError: jest is not defined
![image](https://user-images.githubusercontent.com/39021696/173184257-1265297b-eb4e-4069-83a9-db99a025b115.png)
You might find importing:
import { jest } from '@jest/globals'`
to help. I suspect something is causing the jest injectGlobals
option to not apply.
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