TypeError: plugin.test is not a function when using jest, enzyme and react-16, typescript
TypeError: plugin.test is not a function when using jest, enzyme and react-16, typescript
我正在将我的 React 应用程序更新到 react-16
,但我的所有测试都停止了。我已经升级了 enzyme
、jest-enzyme
、react-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() });
正在写题,意识到错误。在 jestconfig.json
上缺少以下内容
"snapshotSerializers": [
"enzyme-to-json/serializer" // <= this part
],
..rest of code
我正在将我的 React 应用程序更新到 react-16
,但我的所有测试都停止了。我已经升级了 enzyme
、jest-enzyme
、react-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() });
正在写题,意识到错误。在 jestconfig.json
"snapshotSerializers": [
"enzyme-to-json/serializer" // <= this part
],
..rest of code