我在monorepo中使用jazelle和yarn pnp。但是我不能运行像jz test
这样的测试。似乎@types/jest
没有正确设置。
我的错误:
FAIL __tests__/autocomplete/presto/suggest.test.ts
● Test suite failed to run
__tests__/autocomplete/presto/suggest.test.ts:4:8 - error TS6137: Cannot import type declaration files. Consider importing 'jest' instead of '@types/jest'.
4 import '@types/jest';
~~~~~~~~~~~~~
__tests__/autocomplete/presto/suggest.test.ts:6:1 - error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
6 describe('Presto SQL Suggest Tests', () => {
~~~~~~~~
__tests__/autocomplete/presto/suggest.test.ts:7:5 - error TS2593: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig.
7 test('Empty suggest', () => {
~~~~
__tests__/autocomplete/presto/suggest.test.ts:10:9 - error TS2304: Cannot find name 'expect'.
10 expect(result.length).toBe(0);
~~~~~~
我做了搜索,并试图修复我的以下文件的基础上搜索的建议。但不幸的是,我仍然不能解决我的错误。
下面是我的档案:
tsconfig.json
{
"typeAcquisition": {
"include": [
"jest"
]
},
"compilerOptions": {
"types": [
"node",
"@types/jest"
],
"typeRoots": [
"./types",
"./node_modules/@types"
],
"outDir": "target",
"sourceMap": true,
"inlineSources": true,
"noImplicitAny": true,
"strict": true,
"noEmit": true,
"target": "es2015",
"module": "commonjs",
"allowJs": true,
"checkJs": true,
"jsx": "react",
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"baseUrl": ".",
"resolveJsonModule": true,
"experimentalDecorators": true
},
"include": [
"src/**/*.*",
"__tests__"
],
"exclude": [
"node_modules",
"**/*.spec.ts",
"**/*.test.ts"
],
}
我的jest.config.js
module.exports = {
rootDir: './',
testEnvironment: 'node',
preset: 'ts-jest',
transform: {
"^.+\\.(ts|js)$": require.resolve('ts-jest')
},
moduleFileExtensions: [
"ts",
"tsx",
"js"
],
roots: [
"<rootDir>/__tests__"
],
}
我的发展历程:
"@types/jest": "28.1.3",
"@types/mocha": "^2.2.42",
"@jest/globals": "25.5.2",
"antlr4ts-cli": "^0.5.0-alpha.4",
"babel-eslint": "10.1.0",
"babel-jest": "28.1.3",
"babel-plugin-parameter-decorator": "1.0.16",
"create-universal-package": "^4.3.0",
"eslint": "7.32.0",
"eslint-config-fusion": "^6.3.0",
"eslint-config-prettier": "2.10.0",
"eslint-plugin-baseui": "10.12.1",
"eslint-plugin-cup": "2.0.3",
"eslint-plugin-flowtype": "4.7.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jest": "23.20.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-react": "^7.27.0",
"eslint-plugin-react-hooks": "^4.6.0",
"flow-bin": "0.131.0",
"flow-coverage-report": "0.7.0",
"jest": "28.1.3",
"jest-environment-jsdom": "28.1.3",
"jest-environment-jsdom-global": "3.1.2",
有想法吗?谢谢
1条答案
按热度按时间rbl8hiat1#
尝试为每个函数添加显式导入。