TypeError:使用笑话,酶和react-16,打字稿时,plugin.test不是函数

时间:2018-06-21 06:21:47

标签: reactjs typescript jestjs enzyme react-16

我正在将我的React应用更新为react-16,但是我的所有测试都停滞了。我已经升级了enzymejest-enzymereact-dom,安装了enzyme-adapter,创建了setupTest.ts酶文件,更新了我的jestconfig.js文件,但是我我仍然收到错误。如果有人知道可能出什么问题。

进行npm ls时没有依赖性警告(包含反应|测试)

这是我的 jestconfig

{
  "moduleDirectories": [
    "node_modules",
    "src"
  ],
  "moduleFileExtensions": [
    "ts",
    "tsx",
    "js"
  ],
  "moduleNameMapper": {
    "\\.(css|scss)$": "identity-obj-proxy"
  },
  "transform": {
    ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
  },
  "testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js",
  "snapshotSerializers": [
    "enzyme-to-json"
  ],
  "setupTestFrameworkScriptFile":"<rootDir>/config/setupTests.ts",
  "coveragePathIgnorePatterns": ["node_modules", "__tests__"],
  "testRegex": "__tests__/.*\\.test\\.(ts|tsx|js)$",
  "collectCoverageFrom": ["src/**/*.{ts,tsx}"],

...rest of code

src / setupTests.ts

import 'raf/polyfill'; // <= this removes the requestAnimationFrame warning error
import * as Enzyme from 'enzyme';
import * as Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });

1 个答案:

答案 0 :(得分:4)

正在写问题并意识到错误。在jestconfig.json

上缺少以下内容
"snapshotSerializers": [
    "enzyme-to-json/serializer" // <= this part
  ],

..rest of code