@nestjs/testing#TestingModule TypeScript Examples

The following examples show how to use @nestjs/testing#TestingModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.controller.spec.ts    From 42_checkIn with GNU General Public License v3.0 6 votes vote down vote up
describe('AppController', () => {
  let appController: AppController;

  beforeEach(async () => {
    const app: TestingModule = await Test.createTestingModule({
      controllers: [AppController],
      providers: [AppService],
    }).compile();

    appController = app.get<AppController>(AppController);
  });

  describe('root', () => {
    it('should return "Hello World!"', () => {
      expect(appController.getHello()).toBe('Hello World!');
    });
  });
});
Example #2
Source File: app.controller.spec.ts    From nr-apm-stack with Apache License 2.0 6 votes vote down vote up
describe('AppController', () => {
  let appController: AppController;
  const handledVal = {};
  const appService = {
    handleKinesisEvent: jest.fn().mockResolvedValue(handledVal),
  };

  beforeEach(async () => {
    const app: TestingModule = await Test.createTestingModule({
      controllers: [AppController],
      providers: [AppService],
    }).overrideProvider(AppService)
      .useValue(appService)
      .compile();

    appController = app.get<AppController>(AppController);
    jest.clearAllMocks();
  });

  describe('root', () => {
    it('should handleKinesisEvent when print false"', async () => {
      expect(await appController.handleData({}, '')).toBe(handledVal);

      expect(appService.handleKinesisEvent).toHaveBeenCalledTimes(1);
      expect(appService.handleKinesisEvent).toHaveBeenCalledWith({}, false);
    });

    it('should handleKinesisEvent when print true"', async () => {
      expect(await appController.handleData({}, 'true')).toBe(handledVal);

      expect(appService.handleKinesisEvent).toHaveBeenCalledTimes(1);
      expect(appService.handleKinesisEvent).toHaveBeenCalledWith({}, true);
    });
  });
});
Example #3
Source File: application.controller.spec.ts    From nest-nuxt-starter with MIT License 6 votes vote down vote up
describe('ApplicationController', () => {
  let controller: ApplicationController;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [ApplicationService],
      controllers: [ApplicationController],
    }).compile();

    controller = module.get<ApplicationController>(ApplicationController);
  });

  it('should be defined', () => {
    expect(controller).toBeDefined();
  });
});
Example #4
Source File: health.e2e-spec.ts    From nestjs-api-example with MIT License 6 votes vote down vote up
describe('HealthController (e2e)', () => {
  let app: INestApplication;

  beforeAll(async () => {
    const module: TestingModule = await Test.createTestingModule({
      imports: [AppModule],
    }).compile();

    app = module.createNestApplication();
    await app.init();
  });

  afterAll(async () => {
    await app.close();
  });

  it('/health (GET)', () => {
    return request(app.getHttpServer()).get('/health').expect(200).expect('OK');
  });
});
Example #5
Source File: status.controller.test.ts    From nest-react with GNU Lesser General Public License v3.0 6 votes vote down vote up
describe('AppController', () => {
  let statusController: StatusController;

  beforeEach(async () => {
    const app: TestingModule = await Test.createTestingModule({
      controllers: [StatusController],
      providers: [ConfigService, StatusService],
    }).compile();

    statusController = app.get<StatusController>(StatusController);
  });

  describe('root', () => {
    it('should return a nice status world', () => {
      expect(statusController.getStatus()).toBe(
        'Status world from Nest running on localhost:4000!'
      );
    });
  });
});
Example #6
Source File: app.controller.spec.ts    From NestJs-youtube with MIT License 6 votes vote down vote up
describe('AppController', () => {
  let appController: AppController;

  beforeEach(async () => {
    const app: TestingModule = await Test.createTestingModule({
      controllers: [AppController],
      providers: [AppService],
    }).compile();

    appController = app.get<AppController>(AppController);
  });

  describe('root', () => {
    it('should return "Hello World!"', () => {
      expect(appController.getHello()).toBe('Hello World!');
    });
  });
});
Example #7
Source File: ses.service.spec.ts    From nestjs-ses with MIT License 6 votes vote down vote up
describe('SesService', () => {
  let service: SesService;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [SesService],
    }).compile();

    service = module.get<SesService>(SesService);
  });

  it('should be defined', () => {
    expect(service).toBeDefined();
  });
});
Example #8
Source File: auth.controller.spec.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
describe('Auth Controller', () => {
  let controller: AuthController;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [AuthController],
      providers: [
        {
          provide: AuthService,
          useValue: {},
        },
        {
          provide: UsersService,
          useValue: {},
        },
        {
          provide: JwtService,
          useValue: {},
        },
      ],
    }).compile();

    controller = module.get<AuthController>(AuthController);
  });

  it('should be defined', () => {
    expect(controller).toBeDefined();
  });
});
Example #9
Source File: app.controller.spec.ts    From barista with Apache License 2.0 6 votes vote down vote up
describe('AppController', () => {
  let appController: AppController;
  beforeEach(async () => {
    const app: TestingModule = await Test.createTestingModule({
      imports: [
        BullModule.forRoot({
          name: 'test',
          processors: [jest.fn()],
        }),
      ],
      controllers: [AppController],
      providers: [
        AppService,
        LicenseService,
        { provide: getRepositoryToken(License), useClass: mockRepository },
        { provide: getQueueToken('scan-queue'), useValue: { add: jest.fn } },
      ],
    }).compile();

    appController = app.get<AppController>(AppController);
  });

  describe('root', () => {
    it('should instantiate', () => {
      expect(appController).toBeDefined();
    });

    it('should return a result', () => {
      expect(appController.appStatus()).toBeDefined();
    });
  });
});