Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Jest tests fail after adding Typescript to a React Native project

$
0
0

So, I just added TypeScript to an existing React Native project (first commit dates from Feb 2016), and I'm getting the follwing errors when running unit tests (using Jest):

  1. This is the one that is showing in most files, I'd say 30 out of 38 failed testsenter image description here

  2. This one already has a mock in the mock filesenter image description here

  3. This one shows up on two filesenter image description here

  4. This one shows up on just one fileenter image description here

This only happens when adding ts, I've only modified three files from the project to use it as I have to go slowly because it's a huge project.

I've tried out with different setups for jest.config.js but nothing changes:

jest.config.js

const { defaults: tsjPreset } = require('ts-jest/presets');module.exports = {    ...tsjPreset,    globals: {'ts-jest': {            babelConfig: true,        }    },    moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],    modulePaths: ['<rootDir>'],    preset: 'react-native',    transform: {        ...tsjPreset.transform,'^.+\\.(js)$': '<rootDir>/node_modules/babel-jest','^.+\\.(ts|tsx)?$': '<rootDir>/node_modules/ts-jest/preprocessor.js',    },    transformIgnorePatterns: ['node_modules/(?!(texts/@debitoor/react-native-sunstone/))/'],};

tsconfig.json

{"compilerOptions": {"allowJs": true,"allowSyntheticDefaultImports": true,"baseUrl": "./app","esModuleInterop": true,"isolatedModules": true,"jsx": "react","lib": ["es2017"],"moduleResolution": "node","noEmit": true,"paths": {"common": ["./common"]        },"skipLibCheck": true,"strict": false,"target": "esnext"    },"exclude": ["node_modules","babel.config.js","metro.config.js","jest.config.js"    ]}

I tried removing the exclude elements at same thing happens. Not sure what else I'm missing.

I also tried using ts-jest but nothing changed either.

This is the tsconfig.jest.json file:

{"extends": "./tsconfig","compilerOptions": {"jsx": "react","module": "commonjs"    }}

I've searched around and in most articles/sites they always talk about starting fresh, but I've already got everything else setup and can't really change much without taking too much time.

Any ideas would be great!


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>