-
Notifications
You must be signed in to change notification settings - Fork 454
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
Enum breaks ts-jest #1229
Comments
Downgrading to <23.10.0 works for me |
hi @bodinsamuel , I've checked your repo. You have |
Please see the detail of explanation here |
@ahnpnl thanks for the explanation, but what are we supposed to do if the enum is defined in a 3rd-party |
Hi, I think you can ask jest to skip d.ts from transforming. If jest doesn’t give d.ts to ts-jest, typescript compiler api in ts-jest internal wont throw errors. In general, the input files ts-jest processes depending on jest, whatever jest gives, ts-jest will process. |
Oh sorry I was unclear. My use-case is the following: I'm using this enum from the So in my code, in the file I'd like to test, I have: import { [....], State } from "react-native-gesture-handler";
[....]
if (state === State.BEGAN) {
[....] And my test fails on The best workaround I could find is to mock the jest.mock("react-native-gesture-handler", () => ({
PanGestureHandler: () => "PanGestureHandler",
NativeViewGestureHandler: () => "NativeViewGestureHandler",
State: {
UNDETERMINED: 0,
FAILED: 1,
BEGAN: 2,
CANCELLED: 3,
ACTIVE: 4,
END: 5
}
})); |
I don't have any other ways other than your provided workaround :( but I think your workaround looks good. Thanks for sharing. In general, |
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:
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 passingisolatedModules
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
The text was updated successfully, but these errors were encountered: