Skip to content
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

Merged
merged 1 commit into from
Feb 7, 2019
Merged

Added ts-jest #27

merged 1 commit into from
Feb 7, 2019

Conversation

emin93
Copy link
Member

@emin93 emin93 commented Feb 7, 2019

In this PR I re-added ts-jest to enable out of the box jest testing with TypeScript.

@emin93 emin93 merged commit 44e7ad3 into master Feb 7, 2019
@emin93 emin93 deleted the ts-jest branch February 7, 2019 20:21
@@ -4,7 +4,7 @@
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-native",
"jsx": "react",

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? 🙂

Copy link
Member Author

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 😄

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!

@JReinhold
Copy link

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 react-navigation and react-gesture-handler. I'll leave the extra configuration here, in case anyone else comes by with the same problem:

Jest config (in package.json if using this template), gotten from kulshekhar/ts-jest#604 (comment):

...
"transformIgnorePatterns": ["/node_modules/(?!react-native)/.+"],

@emin93
Copy link
Member Author

emin93 commented Feb 12, 2019

Oh that's very good to know! If I understood the regex correctly, it tells Jest to ignore everything that starts with react-native in the node_modules directory? Wouldn't it be better to ignore everything inside the node_modules directory?

@JReinhold
Copy link

It's actually the exact opposite, it tells jest to ignore all modules EXCEPT react-native-files. Notice the ! at the beginning. I think jest defaults to ignore all node_modules, so this regex is basically whitelisting react-native in the transformation.

@emin93
Copy link
Member Author

emin93 commented Feb 21, 2019

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?

@JReinhold
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants