首页 > 解决方案 > 带有 supertest 的 NestJS 无法使用“无法调用类型缺少调用签名的表达式”进行编译

问题描述

当尝试从 NestJS 示例运行 e2e 测试时,我的测试没有编译为该行的“无法调用类型缺少调用签名的表达式”

request(app.getHttpServer())

代码来自 NestJS 测试示例。

这可能与我的 tsconfig 有关?

import * as request from "supertest";
import { Test } from "@nestjs/testing";
import { INestApplication } from "@nestjs/common";

describe("App", () => {
  let app: INestApplication;

  beforeAll(async () => {
    const module = await Test.createTestingModule({
      imports: []
    }).compile();

    app = module.createNestApplication();
    await app.init();
  });

  it(`/GET`, () => {
    return request(app.getHttpServer())
      .get("/")
      .expect(200);
  });

  afterAll(async () => {
    await app.close();
  });
});

标签: typescriptnestjs

解决方案


这修复了它

import request from "supertest";

推荐阅读