question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for "jsx": "preserve" config

See original GitHub issue

After issue #58 I’ve realized that we have no support for this options in config which leads to errors that user can’t understand. Possible solutions:

  1. Find a way to activate babel-jest transformer from jest config after ts-jest applied.
  2. Inform user that this option is not allowed and use "jsx": "react" instead.
  3. Include babel-jest transformer in our package and run it if "jsx": "preserve" is used.

As for me third solution seems to be the worst. First of all we have to create tests for this case.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:18

github_iconTop GitHub Comments

8reactions
kelly-tockcommented, Jul 24, 2018

I can’t seem to get a react element test to work with ts-jest, and tsconfig: preserve. I reproduced the test using https://github.com/wmonk/create-react-app-typescript, so I know my test is ok.

TypeScript compiler encountered syntax errors while transpiling. Errors: '>' expected.,Unterminated regular expression literal.,',' expected.,')' expected.

I tried setting it to react in jsx, still same message.

my transforms:

    "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
    "^.+\\.(ts|tsx)$": "ts-jest",

any ideas what that message means?

non react tests work like a charm thus far.

6reactions
jbrantlycommented, Feb 8, 2017

BTW, I think this issue is bigger than just JSX. There are a lot of other things that Babel can do beyond just JSX (for instance, the actual implementation side of “allowSyntheticDefaultImports”). I tend to use TypeScript for type-checking and Babel for transpilation for this reason.

Additionally, while I was able to easily chain TypeScript and Babel using a custom preprocessor, I can’t quite get code coverage working. So in the case of 1 or 3, some additional work might be needed to make sure code coverage still works. And if anyone has any tips on making that work manually that’d be awesome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - JSX - TypeScript
The preserve mode will keep the JSX as part of the output to be further consumed by another transform step (e.g. Babel). Additionally...
Read more >
what is the use of 'jsx' property in tsconfig.json - Stack Overflow
The preserve mode will keep the JSX as part of the output to be further consumed by another transform step (e.g. Babel).
Read more >
Introducing the New JSX Transform – React Blog
Flow supports the new JSX transform in v0.126.0 and up, by adding react.runtime=automatic to your Flow configuration options. Removing Unused ...
Read more >
babel/plugin-transform-react-jsx
Though the JSX spec allows this, it is disabled by default since React's JSX does not currently have support for it. You can...
Read more >
JSX: The benefits of using it with Vue JS you should explore
If you are using an older version of Vue-cli that doesn't support Vue JSX, ... Setting the jsx option to “preserve” means that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found