Closed zucchinho closed 4 years ago
It is possible this is somehow a ts-jest issue, as it seems odd that it should compile fine during the normal react native build, but not here. Now that I think about it, it seems likely ts-jest is stripping out the type arguments before the calling the babel plugins.
Okay, I overcame this issue pretty easily. Just installed 'ts-nameof' package, and added line to jest config, as per the docs
globals: { 'ts-jest': { babelConfig: true, astTransformers: ['ts-nameof'], diagnostics: { warnOnly: true, }, }, },
I don't think there's any drawbacks to doing it this way, so will close.
Problem
React native project, with typescript. Have installed the babel-plugin-ts-nameof and set it up via babel.config.js, and it seems to work flawlessly for compilation for a real build of the app. However have come across an issue where it is not working during compilation of unit tests, which are run with jest and compiled with ts-jest. i have set the corresponding option in jest.config.js:
globals: { 'ts-jest': { babelConfig: true, diagnostics: { warnOnly: true, }, }, }
This is my babel config:
{ presets: ['module:metro-react-native-babel-preset'], env: { production: {}, }, plugins: [ [ '@babel/plugin-proposal-decorators', { legacy: true, }, ], ['@babel/plugin-proposal-optional-catch-binding'], [ 'babel-plugin-inline-import', { extensions: ['.html'], }, ], ['babel-plugin-ts-nameof'], ], sourceMaps: true, }
Reproduce
Simple test:
it('should correctly recoginize type arguments in nameof transform', () => { type TThing = { something: 'yes' }; expect(nameof<TThing>()).toBe('TThing'); });
Current behaviour
Expected behaviour
Version
babel-plugin-ts-nameof: 4.2.1