导入不使用Jest和Typescript导入

时间:2018-12-19 15:34:52

标签: reactjs typescript jestjs babeljs enzyme

我正在使用Jest,Enzyme和Typescript,但是由于某些原因某些导入无法正常工作……它们是未定义的。例如,我在文件中有import ReactMarkdown from 'react-markdown';,并且在运行测试时,我得到Cannot read property 'createElement' of undefined的{​​{1}}。下面是配置文件

jest.config.js

ReactMarkdown

jest.ts.config.json

/* 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"
  }
};

0 个答案:

没有答案