typescript - 试图让 jest 与 typescript 一起工作,得到描述,毕竟,expect 是未定义的
问题描述
尝试使用 typescript 设置 jest,我的 linter 给了我一些带有描述的红色波浪线,毕竟它说它们是未定义的。
我在这里尝试了一些解决方案ReferenceError: describe is not defined in Jest + Typescript但它们没有用。
我的版本
node: 12.16.3
"@types/jest": "^26.0.7"
"jest": "^26.1.0",
"ts-jest": "^26.1.4",
"typescript": "^3.9.7"
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true
},
"include": [
"node_modules/@types",
"__test__/db/**/**.ts"
]
}
jest.config.js:
module.exports = {
moduleFileExtensions: ['ts', 'js', 'jsx', 'tsx'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
testMatch: ['**/__tests__/**/*.[jt]s?(x)'],
testEnvironment: 'node'
};
我的根测试文件夹看起来像这样
__test__
db
tables
users.test.ts
和我的测试文件的片段应该足够了:
import { Pool } from 'pg';
describe('users table', (): void => {
const conString: string = 'postgres://postgres:postgres@127.0.0.1:5432/testdb';
并且只是装箱我的 .eslintrc.js:
module.exports = {
extends: 'airbnb',
parser: '@typescript-eslint/parser',
env: {
node: true,
es6: true
},
rules: {
'implicit-arrow-linebreak': 'off',
'comma-dangle': 'off',
indent: 'off',
'no-trailing-spaces': 'off'
},
plugins: [
'@typescript-eslint'
]
};
有什么想法吗?谢谢。
解决方案
将 jest: true 添加到 .eslintrc.js 中的 env 对象解决了它。
推荐阅读
- apache-kafka - 在具有不同类型的 JSON 值主题上定义 KSQL STRUCT
- symfony - 输入和输出类的 Symfony 依赖注入
- scala - 使用 Spark xgboost4j 提前停止时如何获取 iter?
- java - FileProvider 无法解析 XML
- java - Apache lucene:对数字和德语变音符号进行排序
- sql - Laravel 将单独的记录合并为一个记录
- spring - 内存中的spring boot activemq
- c# - 是否可以使用 async/await 向 RabbitMQ 发布消息?
- ios - 框架类是否应该导入伞头
- android - 第二页的导航按钮出现在主页上