I have been struggling for a couple of days now to get tests running for simple react-native with expo + typescript + jest + ts-jest. I have already asked a related question here Here is the setup of my project:
- tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"lib": ["dom", "esnext"],
"jsx": "react-native",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
}
}
- babel.config.json
module.exports = function(api) {
api.cache(true);
return {
presets: ["babel-preset-expo"]
};
};
- jest.config.js (see official github setting of react-native + ts-jest)
const { defaults: tsjPreset } = require("ts-jest/presets");
module.exports = {
...tsjPreset,
preset: "react-native",
transform: {
...tsjPreset.transform,
"\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
},
globals: {
"ts-jest": {
babelConfig: true
}
},
cacheDirectory: ".jest/cache"
};
I get this error
ReferenceError: React is not defined
because I am importing react like this in my file:
import React from 'react'
If I import like import * as React from 'react'
it works.
Any help will be greatly appreciated as I have spent already a few days in this project.