question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Environments with TypeScript

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
SimenBcommented, Dec 16, 2020

it didn’t land in 26, but it will be in v27 (you can test it by installing jest@next)

4reactions
SimenBcommented, Mar 26, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create Jest Custom Environment with Typescript?
Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.
Read more >
TypeScript - Environment Setup - Tutorialspoint
Typescript can be built on a plethora of development environments like Visual Studio, Sublime Text 2, WebStorm/PHPStorm, Eclipse, Brackets, etc. Visual Studio ...
Read more >
Parsing .env with TypeScript - DEV Community ‍ ‍
env file and converting it into our own custom Config type that we want to use in the code. import path from "path";...
Read more >
Setting up your TypeScript environment - ArcGIS Developers
This guide provides some basic steps for setting up your TypeScript development environment for use with the %ARCGISJS_SDK_PRODUCT_NAME%.
Read more >
Configuring Jest
It is recommended to define the configuration in a dedicated JavaScript, TypeScript or JSON file. The file will be discovered automatically, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found