sahilrajput03

learn-nestjs

REPOSITORY - https://github.com/sahilrajput03/learn-nestjs/

global interceptors in nestjs:

Interceptors NestJs: Click here

Source: Click here

In file app.module.ts, you can add a suitable provider like that:

image

USAGE:

image

Interceptors can be nested in this way I guess:

image

interceptors in nestjs:

image

http requests, and jest mocking:

    it.only('cool testing', async () => {
      jest.spyOn(httpService, 'get')
      .mockImplementation(() => of({ data: 100, status: 202, statusText: '', headers: {}, config: {} }))
      .mockImplementationOnce(() => of({
        data: 101,
        status: 202,
        statusText: '',
        headers: {},
        config: {},
      }))
      .mockImplementationOnce(() => of({
        data: 102,
        status: 202,
        statusText: '',
        headers: {},
        config: {},
      }));

      const { data: data1 } = await lastValueFrom(httpService.get('/'));
      console.log({ data1 }); // 101

      const { data: data2 } = await lastValueFrom(httpService.get('/'));
      console.log({ data2 }); // 102

      const { data: data3 } = await lastValueFrom(httpService.get('/'));
      console.log({ data3 }); // 100

      const { data: data4 } = await lastValueFrom(httpService.get('/'));
      console.log({ data4 }); // 100
      expect(1).toBe(1);
    });

Other Cool things:

image

image

Swagger Usage