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.

Jest testing with Lingui and TypeScript

See original GitHub issue

I’ve finally got some time allocated to a catch up on unit tests with our Lingui powered TypeScript app and it turned out to be quite a challenge. I do realize it’s not something everyone has experience with, but perhaps some ideas will come out of this.

The issue is that Jest cannot use Webpack configuration to transpile the code. It has it’s own ts-jest transform and adding Babel to the mix is supported only for JS files. Currently, I am trying to use “old” transformation Babel plugins as I don’t feel that macros are ready for a production yet and I don’t like current syntax particularly.

I’ve prepared a repo with minimal showcase and attempt at a solution based on composing ts-jest & babel-jest together, but for some reason, I am unable to make it work. The TypeScript code gets transpiled, but Lingui plugins won’t do its part.

https://github.com/FredyC/ts-jest-lingui

There is also a log file included with an output from both transformations. I am not sure why is it happening.

Also I would like to point out that I don’t want to use Babel with TypeScript transform as there are some caveats and I am not willing to accept those.

cc @huan086 @quentez @ghostd (in case you have some insight here since you made typescript extractor)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
danielkczcommented, Apr 2, 2019

Get rid of ts-jest 😄 I just switched to Babel Typescript and don’t worry about it anymore.

0reactions
kopax-polyconseilcommented, Jun 28, 2021

How do you get ride of ts-jest ? That’s the only way for I to get the test running.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing — LinguiJS documentation
Testing ¶. Components using <Trans>, withI18n() or useLingui() require access to the context of <I18nProvider>. How you can wrap your component with the ......
Read more >
Testing TypeScript apps using Jest - LogRocket Blog
Jest is a simple, lightweight testing framework that provides a variety of testing capabilities to JavaScript and TypeScript projects.
Read more >
lingui/js-lingui - Gitter
Hello I'm using lingui 2.x and trying to mock I18n._ in jest. Any pointers? I am using react-testing-library, if that makes a difference....
Read more >
How to Test React Components in TypeScript | Pluralsight
This installs Jest and React Testing Library with TypeScript support. ... This is a typical Jest configuration but with some additional ...
Read more >
@lingui/macro examples - CodeSandbox
Learn how to use @lingui/macro by viewing and forking @lingui/macro example apps on CodeSandbox. ... react-typescript ... seerviashish/swiggy-test.
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