venkatraman hiregange
venkatraman hiregange

Reputation: 105

TypeError in NestJs project when using jest.mock("common-package") in conjunction with ConfigModule

I am working on a project in NestJs and I am facing a problem. We have a common-package and I have implemented a custom implementation and module for it. The module looks something like this:

@Module({
  imports: [
    ConfigModule.forFeature(ConfigurationLoadedFromYamel),
    HttpModule.register({
      timeout: 5000,
      maxRedirects: 5,
    }),
  ],
  providers: [Providerq, Provider2...],
  exports: [Provider1, Provider2],
})
export class CustomeModule { }

Functionality-wise, everything is working fine. However, we have used jest.mock("common-package") in various test files across different services. The jest tests in the service test files where jest.mock("common-package") is used are failing with the following error:

● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'KEY')

  17 |     (0, common_1.Module)({
  18 |         imports: [
> 19 |             config_1.ConfigModule.forFeature(__1.ConfigurationLoadedFromYamel),
     |                ^
  20 |             axios_1.HttpModule.register({
  21 |                 timeout: 5000,
  22 |                 maxRedirects: 5,

  at createConfigProvider (../../../.yarn/__virtual__/@nestjs-config-virtual-138ce56a57/0/cache/@nestjs-config-npm-1.0.2-c2233e92ab-c0148ff457.zip/node_modules/@nestjs/config/dist/utils/create-config-factory.util.js:9:26)
  at Function.forFeature (../../../.yarn/__virtual__/@nestjs-config-virtual-138ce56a57/0/cache/@nestjs-config-npm-1.0.2-c2233e92ab-c0148ff457.zip/node_modules/@nestjs/config/dist/config.module.js:123:86)
  at Object.<anonymous> (../../../.yarn/__virtual__/......./Path/CustomeModule.js:19.

Could you please help me understand why this issue is happening?

Upvotes: 0

Views: 39

Answers (0)

Related Questions