【问题标题】:TypeError: plugin.test is not a function when using jest, enzyme and react-16, typescriptTypeError: plugin.test is not a function when using jest,酵素和react-16, typescript
【发布时间】:2018-06-21 06:21:47
【问题描述】:

我正在将我的 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() });

【问题讨论】:

    标签: reactjs typescript jestjs enzyme react-16


    【解决方案1】:

    正在写问题并意识到错误。在jestconfig.json 上缺少以下内容

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

    【讨论】:

      猜你喜欢
      • 2021-04-22
      • 2013-10-20
      • 1970-01-01
      • 2016-04-02
      • 2016-09-14
      • 2018-11-02
      • 2020-11-08
      • 2020-11-24
      • 1970-01-01
      相关资源
      最近更新 更多