nestjs icon indicating copy to clipboard operation
nestjs copied to clipboard

MikroOrmMiddleware not found in e2e tests

Open fabianboerner opened this issue 1 year ago • 0 comments

Describe the bug MikroOrmMiddleware in e2e tests for one module cannot be found for MikroOrm

Stack trace

 Nest can't resolve dependencies of the MikroOrmMiddleware (?). Please make sure that the argument MikroORM at index [0] is available in the MikroOrmCoreModule context.

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

      52 |     }).compile()
      53 |
    > 54 |     await module.createNestApplication().init();
         |     ^
      55 |
      56 |     commandBus = module.get<ICommandBus>(CommandBus);
      57 |     queryBus = module.get<IQueryBus>(QueryBus);

      at Injector.lookupComponentInParentModules (node_modules/@nestjs/core/injector/injector.js:254:19)
      at Injector.resolveComponentInstance (node_modules/@nestjs/core/injector/injector.js:207:33)
      at resolveParam (node_modules/@nestjs/core/injector/injector.js:128:38)
          at async Promise.all (index 0)
      at Injector.resolveConstructorParams (node_modules/@nestjs/core/injector/injector.js:143:27)
      at Injector.loadInstance (node_modules/@nestjs/core/injector/injector.js:70:13)
      at Injector.loadMiddleware (node_modules/@nestjs/core/injector/injector.js:84:9)
      at MiddlewareResolver.resolveMiddlewareInstance (node_modules/@nestjs/core/middleware/resolver.js:15:9)
          at async Promise.all (index 0)
      at MiddlewareResolver.resolveInstances (node_modules/@nestjs/core/middleware/resolver.js:12:9)
      at loadMiddlewareConfiguration (node_modules/@nestjs/core/middleware/middleware-module.js:44:13)
          at async Promise.all (index 6)
      at MiddlewareModule.resolveMiddleware (node_modules/@nestjs/core/middleware/middleware-module.js:46:9)
      at MiddlewareModule.register (node_modules/@nestjs/core/middleware/middleware-module.js:38:9)
      at Proxy.registerModules (node_modules/@nestjs/core/nest-application.js:82:9)
      at Proxy.init (node_modules/@nestjs/core/nest-application.js:98:9)
      at Object.<anonymous> (src/features/external-campaign-status/tests/external-campaign-status.e2e-spec.ts:54:5)

To Reproduce Steps to reproduce the behavior:

  1. create test module for nestjs
  2. import your module for testing

Expected behavior MikroOrmMiddleware is correctly injected

Additional context did not test it for the real application but we had a similar setup that worked

Test setup:

    module = await Test.createTestingModule({
      imports: [

        ConfigModule.forRoot({ isGlobal: true }),
        ExternalCampaignStatusModule,
      ],
    }).compile()

    await module.createNestApplication().init();

Versions

Dependency Version
node 18
typescript "typescript": "^5.1.6",
mikro-orm
"@mikro-orm/core": "^6.1.4",
"@mikro-orm/mongodb": "^6.1.4",
"@mikro-orm/nestjs": "^5.2.3", |

| your-driver | mongodb |

fabianboerner avatar Apr 09 '24 13:04 fabianboerner