简体   繁体   English

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

[英]TypeError: plugin.test is not a function when using jest, enzyme and react-16, typescript

I'm in the process of updating my react app to react-16 , but all my tests brake. 我正在将我的react应用程序更新为react-16 ,但是我的所有测试都停止了。 I have upgraded enzyme , jest-enzyme , react-dom , installed the enzyme-adapter , created the setupTest.ts enzyme file, updated my jestconfig.js file but I'm still getting the error. 我已经升级了enzymejest-enzymereact-dom ,安装了enzyme-adapter ,创建了setupTest.ts酶文件,更新了我的jestconfig.js文件,但仍然出现错误。 If anyone has an idea of what might be going wrong. 如果有人知道可能出什么问题。

No dependency warnings (pertaining react|tests) when doing npm ls 执行npm ls时,没有依赖项警告(正在进行反应)

Here is my jestconfig 这是我的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 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() });

Was writing the question and the realised the error. 正在写问题并意识到错误。 Was missing the following on the jestconfig.json jestconfig.json上缺少以下jestconfig.json

"snapshotSerializers": [
    "enzyme-to-json/serializer" // <= this part
  ],

..rest of code

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM