NestJS 11 · Testing

Unit test a service

Build a small testing module with only what the test needs.

const moduleRef = await Test.createTestingModule({
  providers: [CatsService],
}).compile();
const service = moduleRef.get(CatsService);
expect(service.findAll()).toEqual([]);

Official NestJS 11 documentation

More testing commands

All testing commands · NestJS 11 cheatsheet

Was this page helpful?