Nest: [Question | Bug] - getting sub injectable from TestingModule

Created on 28 Oct 2017  路  5Comments  路  Source: nestjs/nest

Hi,
When trying to get a sub injectable (for example Component) it returns null.
For example:

// DatabaseModule
@Module({
  modules: [],
  components: [
    SubService
  ]
})
export class AppModule {
}

// App Module
@Module({
  modules: [
    DatabaseModule
  ]
})
export class AppModule {
}

And then when trying to user createTestingModule:

const module = await Test.createTestingModule({
      modules: [AppModule]
}).compile();

const subService = appModule.get<SubService>(SubService);
concole.log(subModule) // null

I found this workaround:

const dbModule = appModule.select(DatabaseModule);
const subService = dbModule.get<SubService>(SubService);

concole.log(subService) // instance of SubService

So should the get method return also nested components of other dependent modules? If so, this is a bug.

type question 馃檶 todo 馃挌

All 5 comments

Hey @vlio20!
Nope. That's exactly why the select() method exists. There's a note about it here 馃檪

the including imported ones is a bit misleading (maybe only for me)

True, right. Thanks @vlio20, will change this 馃檪

Fixed, will be available in the next update. Thanks again @vlio20

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VRspace4 picture VRspace4  路  3Comments

menme95 picture menme95  路  3Comments

marshall007 picture marshall007  路  3Comments

cdiaz picture cdiaz  路  3Comments

tronginc picture tronginc  路  3Comments