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.

ts-jest should be replaced by Babel

See original GitHub issue

Currently 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:open
  • Created 4 years ago
  • Reactions:11
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
agilgur5commented, Mar 16, 2020

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 change transform to use babel-jest or turn off ts-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.

5reactions
sliktscommented, Mar 17, 2020

Issue about ts-jest vs Babel; quote from repo owner:

Even in its current state, I think using typescript via babel should be the way to go for testing. Type-checking should be separate from testing and tsc can be used for that directly. There’s no benefit in having the test runner also do the type-checking.

Another user about errors:

In local development we’re ok to ignore type errors in tests, cause either they can be caught at a later stage, or tests will fail anyway because something is undefined/missing.

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:

We are eager to get some form of type checking in for test files, but we also don’t want to adopt a library that potentially won’t be maintained going forward. We are exploring other options to satisfy this that better fits in our current ecosystem of tools.

The issue I linked to initially was from before Babel support for TS, and it was just one that I was familiar with.

Read more comments on GitHub >

github_iconTop 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 >

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