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.

Usage with ts-jest

See original GitHub issue

As far as I understood, ts-jest supports typescript transformers with the astTransformers option. I tried to make it work like this in my jest.config.js:

  globals: {
    'ts-jest': {
      astTransformers: {
        before: ['ts-transformer-keys/transformer'],
      },
    },
  },

This did not work and results in the error TypeError: ts_transformer_keys_1.keys is not a function, which happens when the transform is not being applied. Any ideas?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
EdNuttingcommented, Sep 9, 2020

This was brilliant - thank you! Never would’ve figured out how to get this working without your solution.

1reaction
DamianPereiracommented, Sep 7, 2020

I managed to do it, I had to create a file like this:

// ts-jest-keys-trasnformer.js
const keysTransformer = require('ts-transformer-keys/transformer').default;
const name = 'my-key-transformer';
const version = 1;
const factory = (cs) => (ctx) => keysTransformer(cs.tsCompiler.program)(ctx);
module.exports = { name, version, factory };

And add it in jest.config.js like this:

  globals: {
        'ts-jest': {
          // relative path to the ts-jest-keys-transformer.js file
          astTransformers: ['src/react/ts-jest-keys-transformer.js'],
        },
      },

I’ll create a PR adding an example and documentation

Read more comments on GitHub >

github_iconTop Results From Across the Web

ts-jest - npm
A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. Latest version: 29.0.3, ...
Read more >
Testing a Typescript project with Jest (ts-jest) | nerd.vision
If you're unfamiliar with Jest as a testing framework then there's no need to worry, it's very simple to use and well documented....
Read more >
Introduction | ts-jest - GitHub Pages
ts -jest is a Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
Read more >
kulshekhar/ts-jest - GitHub
A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. It supports all features of...
Read more >
Getting Started - Jest
ts -jest is a TypeScript preprocessor with source map support for Jest that lets you use Jest to test projects written in TypeScript....
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