Я пытаюсь написать тестовый блок для страницы входа.Я не могу добавить другие тестовые случаи, поскольку я получаю сообщение об ошибке в первой строке.Ниже мой код login.spec.tsx
import LoginPage from '../pages/login';
import { shallow } from 'enzyme';
describe('Login button', () => {
it('should login successfully', () => {
const button = shallow(<LoginPage />); // Error on this line
});
})
Ниже приведена ошибка, которую я получаю.Но если я закомментирую «неглубокий» код, тест будет пройден.
E:\React Js Project\doorstop\src\__tests__\login.spec.tsx:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import LoginPage from '../pages/login';
^^^^^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
Ниже приведен мой package.json.Ниже приведены все установки и зависимости, которые я сделал в моем проекте.
{
"name": "cliq-ravendb",
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/polyfill": "^7.2.5",
"@types/node": "10.12.9",
"@types/react": "16.7.6",
"@types/react-dom": "16.0.9",
"@types/react-router-dom": "^4.3.1",
"antd": "^3.11.2",
"apollo-cache-inmemory": "^1.3.11",
"apollo-client": "^2.4.7",
"apollo-link": "^1.2.4",
"apollo-link-error": "^1.1.2",
"apollo-link-http": "^1.5.7",
"babel-jest": "^23.6.0",
"graphql": "^14.0.2",
"graphql-tag": "^2.10.0",
"node-sass": "^4.11.0",
"react": "^16.6.3",
"react-apollo": "^2.3.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.1",
"typescript": "3.1.6"
},
"scripts": {
"dev": "concurrently \"npm run start-frontend\" \"npm run start-server\"",
"build": "craco build && cd backend && npm run build",
"start": "node ./build/backend/server.js",
"test": "./node_modules/.bin/jest",
"start-frontend": "craco start",
"start-server": "cd backend && npm run dev",
"postinstall": "cd backend && npm install",
"eject": "react-scripts eject"
},
"jest": {
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\\.(ts|tsx)$": "<rootDir>/test-preprocessor.ts"
},
"transformIgnorePatterns": [
"/node_modules"
],
"testMatch": [
"**/__tests__/*.(ts|tsx|js)"
]
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"@craco/craco": "^3.2.2",
"@types/enzyme": "^3.1.15",
"@types/enzyme-adapter-react-16": "^1.0.3",
"@types/jest": "^23.3.10",
"concurrently": "^4.1.0",
"craco-antd": "^1.9.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"eslint": "^5.6.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"jest": "^23.6.0",
"jest-enzyme": "^7.0.1",
"jest-fetch-mock": "^2.1.0",
"prettier": "^1.15.2",
"react-dom": "^16.7.0",
"ts-jest": "^23.10.5"
},
"proxy": "http://localhost:5000"
}
Пожалуйста, найдите мне решение этой проблемы.Спасибо.