Enum breaks ts-jest
See original GitHub issueIssue
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:
- Created 4 years ago
- Reactions:12
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 ats
file, that will make it easier to use when distributing a package via npm.hi @bodinsamuel , I’ve checked your repo. You have
tet.d.ts
but you don’t havetet.ts
which causes the error. If you put your enum intotet.ts
it will work.d.ts
extension is type definition file, I wouldn’t put enum definition intod.ts
to avoid issues. I will close this issue as it’s working.