NestJS 11 · Testing

Replace a dependency with a fake

Provide a mock in place of the real provider.

const moduleRef = await Test.createTestingModule({
  controllers: [CatsController],
  providers: [{ provide: CatsService, useValue: { findAll: () => ['cat'] } }],
}).compile();

Official NestJS 11 documentation

More testing commands

All testing commands · NestJS 11 cheatsheet

Was this page helpful?