Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs CRA忽略jest.config文件_Reactjs_Typescript_Jestjs_Create React App_Enzyme - Fatal编程技术网

Reactjs CRA忽略jest.config文件

Reactjs CRA忽略jest.config文件,reactjs,typescript,jestjs,create-react-app,enzyme,Reactjs,Typescript,Jestjs,Create React App,Enzyme,我将react 16与typescript和Ezyme一起使用,但jest并没有在适配器所在的位置读取setupTests.ts文件。如果我在所有测试开始时尝试配置适配器,它会工作,但当我尝试这样做时,它会给我一个适配器配置错误的提示。在使用typescript时,我需要一些特定的配置还是什么 package.json { "name": "web-to-do", "version": "0.1.0",

我将react 16与typescript和Ezyme一起使用,但jest并没有在适配器所在的位置读取setupTests.ts文件。如果我在所有测试开始时尝试配置适配器,它会工作,但当我尝试这样做时,它会给我一个适配器配置错误的提示。在使用typescript时,我需要一些特定的配置还是什么

package.json

{
  "name": "web-to-do",
  "version": "0.1.0",
  "private": true,
  "homepage": "https://lucasgseabra.github.io/to-do-web/",
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.32",
    "@fortawesome/free-solid-svg-icons": "^5.15.1",
    "@fortawesome/react-fontawesome": "^0.1.14",
    "@reduxjs/toolkit": "^1.5.0",
    "@types/jest": "^26.0.20",
    "@types/node": "^14.14.31",
    "@types/react": "^17.0.2",
    "@types/react-dom": "^17.0.1",
    "axios": "^0.20.0",
    "bootstrap": "^4.5.3",
    "font-awesome": "^4.7.0",
    "react": "^16.14.0",
    "react-bootstrap": "^1.3.0",
    "react-dom": "^16.14.0",
    "react-redux": "^7.2.2",
    "react-router-dom": "^5.2.0",
    "react-scripts": "3.4.3",
    "ts-jest": "^26.5.3",
    "typescript": "^4.2.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "lint": "./node_modules/.bin/eslint src/*.tsx",
    "test": "react-scripts test",
    "test:watch": "jest --watch",
    "eject": "react-scripts eject",
    "predeploy": "yarn build",
    "deploy": "gh-pages -d build"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@types/enzyme": "^3.10.8",
    "@types/enzyme-adapter-react-16": "^1.0.6",
    "@types/react-bootstrap": "^0.32.25",
    "@types/react-redux": "^7.1.16",
    "@types/react-router": "^5.1.12",
    "@types/react-router-dom": "^5.1.7",
    "@types/react-test-renderer": "^17.0.1",
    "@types/redux-promise": "^0.5.29",
    "@types/redux-thunk": "^2.1.0",
    "@typescript-eslint/eslint-plugin": "^4.16.1",
    "@typescript-eslint/parser": "^4.16.1",
    "babel-eslint": "^10.1.0",
    "enzyme": "^3.11.0",
    "enzyme-adapter-react-16": "^1.15.6",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-config-airbnb-base": "^14.2.1",
    "eslint-config-prettier": "^8.1.0",
    "eslint-import-resolver-typescript": "^2.4.0",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-jsx-a11y": "6.2.3",
    "eslint-plugin-prettier": "^3.3.1",
    "eslint-plugin-react": "7.21.5",
    "eslint-plugin-react-hooks": "2.5.0",
    "gh-pages": "^3.1.0",
    "prettier": "^2.2.1",
    "react-test-renderer": "^17.0.1"
  }
}
Jest.config.ts

 module.exports = {
  rootDir: 'src/tests',
  testRegex: '/src/tests/.*test\\.tsx$',
  setupFiles: ['<rootDir>/setupTests.ts'],
};

您必须更改测试脚本以接受配置。像这样
react脚本测试--config jest.config.js

请注意额外的
--
参数

/* eslint-disable import/no-extraneous-dependencies */
import Adapter from 'enzyme-adapter-react-16';
import { configure } from 'enzyme';

configure({ adapter: new Adapter() });