nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.69k stars 7.63k forks source link

Injection not working in tests with Injection Scopes #2639

Closed xxluke closed 5 years ago

xxluke commented 5 years ago

Bug Report

Current behavior

After setting a service to the scope "Request", tests which use this service will fail with a message like TypeError: Cannot read property 'getHello' of undefined.

Input Code

Example repo: https://github.com/xxluke/nestjs-typescript-starter

I changed the code of the service to this:

@Injectable({scope: Scope.REQUEST})
export class AppService {
  @Inject(REQUEST)
  private readonly request: Request;

  getHello(): string {
    return 'Hello World!';
  }
}

Expected behavior

No errors.

Environment

Nest version: 6.5.3

For Tooling issues:
- Node version: 10
kamilmysliwiec commented 5 years ago

Working on this https://github.com/nestjs/nest/pull/2387

immanuel192 commented 5 years ago

Remove package-lock.json, install packages and I can see it works

xxluke commented 5 years ago

This is still not working in NestJS 6.6.4 even though all linked issues/pull requests are closed/merged.

kamilmysliwiec commented 5 years ago

@xxluke you should use await app.resolve() instead of app.get()