supertest에서 "Type 'typeof supertest' has no call signatures."오류

발생한 오류



갑자기 supertest가 오류를 토했다.
 FAIL  test/app.e2e-spec.ts
   Test suite failed to run

    TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
    test/app.e2e-spec.ts:20:16 - error TS2349: This expression is not callable.
      Type 'typeof supertest' has no call signatures.

    20         return request(app.getHttpServer())
                      ~~~~~~~

      test/app.e2e-spec.ts:2:1
        2 import * as request from 'supertest';
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.



환경


"typescript": "^3.7.4"
- "@types/supertest": "^2.0.8"
+ "@types/supertest": "^2.0.10"
"supertest": "^4.0.2"

해결 방법



request.default 와 같은 형태로 호출하도록 변경한다.
it('/ (GET)', () => {
    return request.default(app.getHttpServer())
    .get('/')
    .expect(200)
    .expect('Hello World!');
});

한 사람



본체쪽에서 변경이 있었는지…
1시간 이상 녹았다…

좋은 웹페이지 즐겨찾기