I am using Jest, Enzyme and Typescript, but for some reason certain imports are not working... they are undefined. For example, I have import ReactMarkdown from 'react-markdown';
in a file and when I run the tests, I get Cannot read property 'createElement' of undefined
for ReactMarkdown
. Below are the configuration files
jest.config.js
/* tslint:disable */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: [
"ts",
"tsx",
"js"
],
transform: {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.svg$": "jest-svg-transformer"
},
testMatch: [
"**/*.(test|spec).(ts|tsx)"
],
globals: {
"ts-jest": {
babelConfig: true,
tsConfig: "jest.tsconfig.json"
}
},
coveragePathIgnorePatterns: [
"/node_modules/",
"enzyme.js"
],
setupTestFrameworkScriptFile: "<rootDir>/enzyme.js",
coverageReporters: [
"json",
"lcov",
"text",
"text-summary"
],
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/mocks.js",
"\\.(css|less|scss)$": "<rootDir>/__mocks__/mocks.js"
}
};
jest.ts.config.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "commonjs",
"target": "esnext",
"jsx": "react",
"sourceMap": false,
"experimentalDecorators": true,
"noImplicitUseStrict": true,
"removeComments": true,
"moduleResolution": "node",
"lib": [
"es2017",
"dom"
],
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"node_modules",
"out",
".next"
]
}
allowSyntheticDefaultImports:true
in your tsconfig.json? – Interpleader