Comments (5)
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
from ts-transformer-keys.
This was brilliant - thank you! Never would've figured out how to get this working without your solution.
from ts-transformer-keys.
Glad I could help :)
from ts-transformer-keys.
Unfortunately, this didn't work for me. program is undefined in this test
● Test suite failed to run
TypeError: Cannot read property 'program' of undefined
2 | const name = 'my-key-transformer';
3 | const version = 1;
> 4 | const factory = cs => ctx => keysTransformer(cs.tsCompiler.program)(ctx);
| ^
5 | module.exports = { name, version, factory };
6 |
at ts-jest-keys-transformer.js:4:60
at node_modules/typescript/lib/typescript.js:96726:37
at node_modules/typescript/lib/typescript.js:96819:78
at Array.map (<anonymous>)
at Object.transformNodes (node_modules/typescript/lib/typescript.js:96819:52)
at emitJsFileOrBundle (node_modules/typescript/lib/typescript.js:97443:32)
at emitSourceFileOrBundle (node_modules/typescript/lib/typescript.js:97395:13)
at forEachEmittedFile (node_modules/typescript/lib/typescript.js:97147:34)
at Object.emitFiles (node_modules/typescript/lib/typescript.js:97376:9)
at emitWorker (node_modules/typescript/lib/typescript.js:103688:33)
Edit:
I'm using the following packages:
jest
: 27.1.0
ts-transformer-keys
: 0.4.3
typescript
: 4.0.2
from ts-transformer-keys.
ts-jest 27.x.x has breaking changes. Update:
- const factory = cs => ctx => keysTransformer(cs.tsCompiler.program)(ctx);
+ const factory = cs => ctx => keysTransformer(cs.program)(ctx);
from ts-transformer-keys.
Related Issues (20)
- Can't import keysTransformer in a normal way HOT 2
- Keys transformer includes `never` typed keys
- How do you get node to call a `.ts` file without node-ts?
- Calling instance method from getter in VueSingleFileComponent causes error: Cannot find module HOT 6
- How to use with this with React + Typescript? HOT 2
- how can this be used with ts-node (for node worker_threads ?)
- Warning when using with AWS Lambda and Parcel HOT 1
- Support for gulp HOT 1
- Get required Properites HOT 1
- Fix README spelling error HOT 1
- Would it work with esbuild-loader?
- throw/warn on generics
- TypeArguments is always empty in vite, but can be in rollup HOT 3
- Tests failed in windows 10
- How to get required and optional properties HOT 3
- Cannot find module 'ts-transformer-keys'.
- (0 , _tsTransformerKeys.keys) is not a function HOT 28
- Uncaught (in promise) TypeError: keys is not a function at setup (index.vue:18:1) in Vue 3 app HOT 2
- deprecation warnings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-transformer-keys.