Ts-jest: Custom Environments with TypeScript

Created on 24 Mar 2020  ยท  4Comments  ยท  Source: kulshekhar/ts-jest


I have checked the troubleshooting guide, it does not solve this issue.

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.

Expected behavior :

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

Debug log:


log file content

N/A

jest.config.js

module.exports = {
  preset: 'ts-jest',
  testMatch: [
    '<rootDir>/tests/**/*.spec.ts',
  ],
  testRunner: 'jest-circus/runner',
  testEnvironment: './scripts/custom-environment.ts',
  moduleDirectories: [
    '.',
    './node_modules',
    './utils',
    './interfaces',
  ],
...
};

Minimal repo

https://github.com/stangerjm/ts-jest-custom-env

npm install
npx jest

Most helpful comment

It will be supported in Jest 26: https://github.com/facebook/jest/pull/8751

All 4 comments

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!

Was this page helpful?
0 / 5 - 0 ratings