Я пытаюсь настроить фермент для моего проекта машинописи React.Но я получаю следующую ошибку: TypeError: Cannot read property 'split' of undefined
.
Мой тестовый пример довольно прост, просто используйте «мелкий» для тестирования компонента HelloWorld.Любая помощь будет принята с благодарностью!
TypeError: Cannot read property 'split' of undefined
1 | const Enzyme = require('enzyme');
> 2 | const Adapter = require('enzyme-adapter-react-16');
| ^
3 |
4 | Enzyme.configure({ adapter: new Adapter() });
at new Range (node_modules/enzyme-adapter-utils/node_modules/semver/semver.js:800:20)
at intersects (node_modules/enzyme-adapter-utils/node_modules/semver/semver.js:1334:8)
at Object.<anonymous> (node_modules/enzyme-adapter-utils/build/wrapWithSimpleWrapper.js:37:39)
at Object.<anonymous> (node_modules/enzyme-adapter-utils/build/Utils.js:47:30)
at Object.<anonymous> (node_modules/enzyme-adapter-utils/build/index.js:4:18)
at Object.<anonymous> (node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:47:27)
at Object.<anonymous> (node_modules/enzyme-adapter-react-16/build/index.js:4:18)
at Object.require (setupTests.js:2:18)
at Array.forEach (<anonymous>)
Я использую следующие версии:
react: "16.8.4"
react-dom: "16.8.4"
react-test-renderer: "16.8.4"
enzyme: "3.9.0"
enzyme-adapter-react-16: "1.11.0"
И это моя конфигурация Jest:
jest.config.js:
module.exports = {
"roots": [
"<rootDir>/src"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
"^.+\\.tsx?$": "ts-jest",
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/config/jest/assetsTransformer.js'
},
"testPathIgnorePatterns": [
"/node_modules/",
"/lib/"
],
"testRegex": "(/__tests__/.*(test|spec))\\.(ts|tsx|js)$",
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"ts",
"tsx",
"jsx",
"js",
"json"
],
"setupFilesAfterEnv": ["<rootDir>/setupTests.js"],
"snapshotSerializers": ["enzyme-to-json/serializer"],
"moduleNameMapper": {
"\\.(js)$": "<rootDir>/src/__mocks__/fileMock.js",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/src/__mocks__/fileMock.js",
"\\.(scss|css|less)$": "<rootDir>/src/__mocks__/styleMock.js"
},
"cacheDirectory": "<rootDir>/tmp"
}