ts-jest should be replaced by Babel
See original GitHub issueCurrently ts-jest
is used for tests, and it has a long-standing issue that it doesn’t support a sensible workflow for making changes: https://github.com/kulshekhar/ts-jest/issues/798
If I’m making breaking changes to the code and want to focus on a specific test suite or case, there’s no way to filter out the “diagnostics” from the other test cases, so the output can become flooded with messages.
The solution is to let Babel handle TS, since it doesn’t flood the Jest output with type errors.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:11
- Comments:18 (4 by maintainers)
Top Results From Across the Web
Babel7 or TypeScript | ts-jest - GitHub Pages
With Babel, files are transpiled as isolated modules, there is no notion of "project". With TypeScript, files are part of a project and...
Read more >Migrating a react code base test from using `ts-jest` to babel-jest
Worked recently on a project where I have to use React with TypeScript and I had to write test with Jest, my first...
Read more >Setting up Jest unit tests in a React + Typescript project
babel -jest is like ts-jest , but uses babel to transform files - handy if you have a project with some mixed typescript...
Read more >Code Transformation - Jest
While babel-jest by default will transpile TypeScript files, Babel will not verify the types. If you want that you can use ts-jest ....
Read more >Switching a Jest Project from Babel to SWC - Goldblog
I also don't want tests to be slowed down by type checking, though we should note ts-jest can disable type checking.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, I’ll have to disagree that it “should” be replaced. That’s a very strong sentiment and Babel has a bunch of caveats, from not type-checking to being semantically different to not respecting
tsconfig.json
. TSDX supports lots of users and I don’t think those significant trade-offs make sense for a default setting. Strict defaults also mean solid best-practices out-of-the-box, which is the optimal experience.You can customize your Jest config with a
jest.config.js
and changetransform
to usebabel-jest
or turn offts-jest
’s diagnostics if that’s what you’re looking for. That’s advanced usage and different from the defaults, so I think it makes sense that you’d have to configure that and that it’s not available out-of-the-box.I’ll also disagree with your characterization of that issue as “long-standing” – it was responded to immediately and you were told that what you were seeking is impossible. You didn’t respond with further clarifications, didn’t provide a repro there or here, and there have been no up-votes in 1.5 years. I’m also fairly certain that
tsc
behaves the same exact way: any files that are imported will be type-checked. Maybe your problem is different from that, but without a repro or clarification, it’s difficult to understand what else might be the case.In any case, sounds more like an upstream issue than here. You can customize Jest with a
jest.config.js
, so there’s already a way to work through your specific use case.Issue about ts-jest vs Babel; quote from repo owner:
Another user about errors:
Here’s a CRA feature request about type checking in tests where ts-jest’s possible legacy status is cited by a dev to rule it out:
The issue I linked to initially was from before Babel support for TS, and it was just one that I was familiar with.