-
Notifications
You must be signed in to change notification settings - Fork 397
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
Added ts-jest #27
Added ts-jest #27
Conversation
@@ -4,7 +4,7 @@ | |||
"allowSyntheticDefaultImports": true, | |||
"esModuleInterop": true, | |||
"isolatedModules": true, | |||
"jsx": "react-native", | |||
"jsx": "react", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to get a deeper understanding, may I ask why this change is necessary? 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found out that ts-jest
can't recognize JSX/TSX when this is set to react-native
. You can easily reproduce it by switching it back to react-native
and running npm test
/ yarn test
, it will throw a unexpected Token <
-error. I really appreciate your interest 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh great, I've had that exact problem before, I din't know it had anything to do with that setting. I'll have to try it out tomorrow!
This works great in my current project. Although I had to add an extra configuration to make it work with some of the more advanced libraries like Jest config (in ...
"transformIgnorePatterns": ["/node_modules/(?!react-native)/.+"], |
Oh that's very good to know! If I understood the regex correctly, it tells Jest to ignore everything that starts with |
It's actually the exact opposite, it tells jest to ignore all modules EXCEPT |
Sorry for my delayed answer, had quite a lot of action going on 😅 Ah I see, thanks for the explanation! I'm curious to know why ts-jest needs those files and if it makes sense to include that whitelisting config as a default in the template? |
Yeah, I can't really tell for sure, why it needs that. I see that line in a lot of places and example repos, but can't find a specific answer to WHY its there. IMHO it should be part of the default, because my experience is that you won't get very far without it. As you've experienced, you can test the classic hello world app without the transformIgnorePatterns, but anything beyond that will break in my experience. |
In this PR I re-added
ts-jest
to enable out of the box jest testing with TypeScript.