小编Mik*_*hum的帖子

NestJs + TypeScript + Jest - TypeError:类扩展值未定义不是构造函数或 null

当我尝试向我的 NestJs 应用程序添加一些测试时遇到错误。有一个名为app.controller.spec.ts自动生成的测试文件,它是一个单元测试。当我尝试使用纱线测试命令运行测试时,它会抛出一个错误,指出:

测试套件无法运行 TypeError:类扩展值未定义不是构造函数或 null

 at Object.<anonymous> (../node_modules/@nestjs/testing/services/testing-logger.service.js:7:38)
 at Object.<anonymous> (../node_modules/@nestjs/testing/testing-module.builder.js:9:34)
Run Code Online (Sandbox Code Playgroud)

我的 tsconfig 配置:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true
  },
  "exclude": [
    "node_modules",
    "./node_modules",
    "./node_modules/*",
    "./node_modules/@types/node/index.d.ts",
  ]
}
Run Code Online (Sandbox Code Playgroud)

纱线测试命令: "test": "jest"

单元测试文件内容:

import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import {ConfigModule} from './config/config.module'; …
Run Code Online (Sandbox Code Playgroud)

unit-testing typescript jestjs nestjs

4
推荐指数
1
解决办法
2792
查看次数

标签 统计

jestjs ×1

nestjs ×1

typescript ×1

unit-testing ×1