-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with exporting and importing enums #281
Comments
@kulshekhar I have created a small repo reproducing this issue. This issue only happens for us only when running the unit tests. |
Thanks for the repo. I was able to replicate this issue and dig into it a bit. I think that this comment in the Typescript repo explains the cause of this issue. Given that this is more of a Typescript issue, I'm not sure there's much we can do here |
From that comment, it appears that the TypeScript team has no intention of fixing this, and I don't really see how they could given that As this issue comment suggests, it isn't always safe to use |
Would it be workable to change the preprocessor to use a different compiler api - but just passing in the test file and a preconfigured list of files containing const enums? Or would that still kill performance? I remember a comment in another issue which suggested they rewrote the const enums after compilation using a webpack plugin - maybe that would be more viable? |
@rikkit if there's a workable solution, we can find a way to get that in |
faced with same problem. But not with enums but with using my library (https://github.com/goloveychuk/tsruntime) which uses custom transformers api.
|
https://github.com/goloveychuk/awesome-ts-jest |
This might be solved by #505 |
You can test with beta version (see #697) which handles |
I faced the same problem with enum in unit tests. The problem was the services with the enum var were mocked, and the mock did not have the enum var. on ServiceA.ts
and also on ServiceAMock.ts
|
I had the same problem.
|
@yoasia This issue is fixed with version 23.10 - try upgrading if you haven't already. |
I can confirm this is still an issue for version "24.0.2". |
Any update on this once, we're still facing the issue in our Vue project? |
What's the issue @germain-receeve @thefill ? 23.10 works for me, referencing const enums in test files with no problem. What's the difference? |
To give a bit more context, we had an issue with one of our dependency ,for the example let's call it We ended up solving the issue by updating our setupFiles: ["core-js"],
transformIgnorePatterns: ["/node_modules/(?!(DEPENDENCY_NAME)/)"],
globals: {
"ts-jest": {
isolatedModules: true
}
} Hope this can help other people! |
Why is it closed? I can't use exported enum in my tests actions.ts: export const enum DefinitionActionType {
LOADING_DEFINITIONS = 'definitions/LOADING_DEFINITIONS',
LOADED_DEFINITIONS = 'definitions/LOADED_DEFINITIONS',
} When running normally it's fine, but when i run tests it fails:
|
I'm seeing the same problem with version Seems to only happen when |
I found a workaround that sort of makes things okay: It works if you have a module file that only exports enums
|
There is a note that if using enum inside .d.ts won’t work, but const enum will work. |
i have same issue! |
@ahnpnl @v7lin same here. |
Const enum doesn’t work with isolatedModules: true because typescript transpile API doesn’t support it, you can check in the documentation. @lucasriondel are you using isolatedModules: true ? |
…r importing it based on these 2 issues seems its a TS thing kulshekhar/ts-jest#281 microsoft/TypeScript#5243 (comment)
I still have same issue. what's the solution and is it documented somewhere? |
@safareli are you using |
@ahnpnl, no I don't have it in my |
I meant If you have it as If you have it as |
@ahnpnl 🤦 so the issue was that I had one file "foo.json" and "foo.ts" in same folder and when I was compiling using |
@safareli you gave me the idea of checking this in my code because I had the same problem. Turns out we had too many |
I can confirm the issue remains in version "26.2.0". |
Experiencing this issue in "27.0.5" when exporting default const enums. Seems to work properly when just exporting default enums (not const) |
Thank you for all suggestions, they solved my problem! I'll leave what helped me for others to find.
|
I am also still seeing this issue. I just My enum that I am exporting is not with const:
|
Im using ts-jest 27.1.4, it still shows the error. isolatedModules doesnt affect any. im using |
I have the same issue with an |
same here
export enum Services {
AUTH = 'AUTH',
STATISTICS = 'STATISTICS',
} |
Hi people. On my end the issue was only happening for .ts files and not for .tsx |
yes, i have this problem too, but I don't know how to solve it either. |
Just put enum in separate file. It works for me. |
Still happen in ts-jest v29. Why is this issue closed ? |
The only workaround I have found is to mock the enum in the test file and declare it as a object. Trying to mock it in anyway in a mock file failed to work and declaring it as an enum in the test file also failed to work. |
Still happens to:
This is very annoyning and frustrating issue. |
Still happening :/ How the fundamental thing in TS can not work for years I can't understand |
Only thing that works for me is putting the enum in a .ts file (and not in tsx) |
TypeScript Version: 2.4.1
Code
Expected behavior:
Colors and Numbers should not be undefined in file2.
Colors should be:
Numbers should be
Actual behavior:
Colors and Numbers are undefined.
Any enum entry requested fail with "Cannot read property 'enum entry' of undefined".
It seems that this only occurs in case of a circular dependency.
If you remove the circular dependency everything seems to work fine.
The text was updated successfully, but these errors were encountered: