当尝试从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();
});
});
答案 0 :(得分:0)
您必须导入模块。
import * as request from "supertest";
import { Test } from "@nestjs/testing";
import { INestApplication } from "@nestjs/common";
import { AppModule } from '../src/app.module';
describe("App", () => {
let app: INestApplication;
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [AppModule] // <- this
}).compile();
app = module.createNestApplication();
await app.init();
});
it(`/GET`, () => {
return request(app.getHttpServer())
.get("/")
.expect(200);
});
afterAll(async () => {
await app.close();
});
});
答案 1 :(得分:0)
此问题已解决
import request from "supertest";