nest-winston icon indicating copy to clipboard operation
nest-winston copied to clipboard

Nest can't resolve dependencies of the service

Open JSEvgeny opened this issue 3 years ago • 3 comments

Hey.

I'm using the first approach from readme with WinstonModule.forRoot for app.module. I then inject it in my email service thru dependency injection in constructor and everything works as charm so no issue with that.

But my email.service.spec is now failing with error Nest can't resolve dependencies of the EmailService

Potential solutions: - If winston is a provider, is it part of the current RootTestModule? - If winston is exported from a separate @Module, is that module imported within RootTestModule? @Module({ imports: [ /* the Module containing winston */ ] })

But nothing from those hits helped me. Any ideas of what could go wrong there?

JSEvgeny avatar Jul 01 '21 10:07 JSEvgeny

In addition to the issue. I was able to successfully mock the logger for module I was using it with, but then another module that is dependent on the first one, has broken tests again even when I use the same mocking approach

JSEvgeny avatar Jul 02 '21 06:07 JSEvgeny

Hi @JSEvgeny is this still relevant?

gremo avatar Jul 20 '21 13:07 gremo

@gremo this is relevant for me at this moment. Could you please clarify what is the proper way to test code that injects the following way: @Inject( WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService) {}

Is there any way to avoid writing NestModule.forRoot(...) every time? Ideally, I would want to have the same logger config in my tests as in my app module by default and mock / override logger if needed.

alesdakshanin avatar Nov 18 '21 19:11 alesdakshanin

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jul 07 '23 01:07 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Jul 14 '23 01:07 github-actions[bot]