Skip to content
Snippets Groups Projects
app.controller.spec.ts 851 B
Newer Older
  • Learn to ignore specific revisions
  • Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    import { Test, TestingModule } from '@nestjs/testing';
    import { AppController } from './app.controller';
    describe('AppController', () => {
      let app: TestingModule;
    
      beforeAll(async () => {
        app = await Test.createTestingModule({
          controllers: [AppController],
        }).compile();
      });
    
    
      describe('healthcheck', () => {
        it('should return "Hello World!"', async () => {
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
          const appController = app.get<AppController>(AppController);
    
          const result = { status: 'API Online', uptime: 1, version: '' };
          jest
            .spyOn(appController, 'healthcheck')
            .mockImplementation(async (): Promise<{ status; uptime; version }> => result);
          const healthcheck = await appController.healthcheck();
          expect(healthcheck.status).toBe(result.status);
          expect(healthcheck.uptime).toBe(result.uptime);
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
        });
      });
    });