Home > OS >  Nestjs can't resolve dependencies of the AppConfigService (Unit Testing)
Nestjs can't resolve dependencies of the AppConfigService (Unit Testing)

Time:01-31

I am trying to set up Jest Unit Testing to my project, but I'm getting the following errors when trying to Unit Test:

Erro Message (Screenshot)

How do I fix this issue?

CodePudding user response:

You need to add some sort of mock/provider for the ConfigService. At the very least, this will make the test attempt to work.

{
  provide: ConfigService,
  useValue: {},
}

CodePudding user response:

When you initialise the AppConfigService in test, you need to wire up the providers as well. If you dont need to mock you can directly provide the class in the providers list. If you need mocking, you can use the following dummy code. Refer here for nestjs testing documentation

    providers: [
    {
      provide: AppConfigService,
      useValue: createMock<AppConfigService>({
       <method_name>: jest.fn(),
      }),
    },
  • Related