I have checked the troubleshooting guide, it does not solve this issue.
When creating a custom environment in TypeScript, Jest throws an error complaining about the TypeScript syntax. It appears that the custom environment is not being compiled.
FAIL tests/ticket-search/advanced-search.spec.ts
โ Test suite failed to run
custom-environment.ts:9
async setup(): Promise<void> {
^
SyntaxError: Unexpected token ':'
at node_modules/jest-runner/build/runTest.js:259:7
N/A
jest.config.jsmodule.exports = {
preset: 'ts-jest',
testMatch: [
'<rootDir>/tests/**/*.spec.ts',
],
testRunner: 'jest-circus/runner',
testEnvironment: './scripts/custom-environment.ts',
moduleDirectories: [
'.',
'./node_modules',
'./utils',
'./interfaces',
],
...
};
https://github.com/stangerjm/ts-jest-custom-env
npm install
npx jest
hi, this issue doesn't belong to ts-jest scope. You should check with jest team whether or not they support custom environment with ts. If they support it and pass it to transformer, ts-jest will then can handle it.
I would suggest you to open the issue for jest team.
tag @SimenB has jest already taken into account of this feature ?
It will be supported in Jest 26: https://github.com/facebook/jest/pull/8751
This is fantastic, thanks for pointing this out!
Most helpful comment
It will be supported in Jest 26: https://github.com/facebook/jest/pull/8751