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.

Enum breaks ts-jest

See original GitHub issue

May be related to #944 #962

Issue

I struggled to find a good reason why ts-jest was failing. I first thought my aliases were the source of it. But I reproduced the bug, and finally understood. Accessing an ENUM value is breaking ts-jest.

const a = MyEnum['value'];

It throws:

Cannot find module '../types/tet' from
However, Jest was able to find:

Expected behavior

Well, working obviously 🥺 I found many old issues talking about enum, but nothing in the doc mentioning that specifically. There is a mention of const enum which is not exactly my case here. And passing isolatedModules to false or true does not change the outcome.

Minimal repo

Here is the smallest repo possible, with all explanation in it (install and run basically) https://github.com/bodinsamuel/ts-jest-not-working-with-enum/tree/master

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:7

github_iconTop GitHub Comments

7reactions
ahnpnlcommented, Feb 4, 2020

I don’t have any other ways other than your provided workaround 😦 but I think your workaround looks good. Thanks for sharing. In general, d.ts should be generated from a ts file, that will make it easier to use when distributing a package via npm.

1reaction
ahnpnlcommented, Dec 31, 2019

hi @bodinsamuel , I’ve checked your repo. You have tet.d.ts but you don’t have tet.ts which causes the error. If you put your enum into tet.ts it will work. d.ts extension is type definition file, I wouldn’t put enum definition into d.ts to avoid issues. I will close this issue as it’s working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Undefined TypeScript enum at compile time - Stack Overflow
When I run tests (via jest ) for this project, state.ts generates an error TypeError: Cannot read property 'Both' of undefined , telling...
Read more >
Mock exported enum in tests : r/reactjs - Reddit
I have a .ts file that exports an enum, which I than import from a private node module, the export looks like this....
Read more >
ts-jest users cannot use Level (const enum) when ... - Issuehunt
This would be a breaking change as TS users would no longer be able to use Level.Basic in place of 1 like they...
Read more >
How to Use Enum in TypeScript - Software Testing Help
In this tutorial, we'll be going over the TypeScript Enum by looking at code examples ... Case car Mercedes, console log Mercedes, break....
Read more >
Testing with Jest and TypeScript, the tricky parts
When using Jest with TypeScript, I encountered some struggles and ... npm install --save-dev jest typescript ts-jest @types/jest npx ts-jest ...
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