title: How to use value which returned from controller? Testing controllers on NestJs
body: <p>Controller and method for testing:</p>
  
  <pre><code>import { Controller, Get, Response, HttpStatus, Param, Body, Post, Request, Patch, Delete, Res } from '@nestjs/common';
  @Controller('api/parts')
  export class PartController {
    constructor(private readonly partsService: partsService) { }
  
    @Get()
    public async getParts(@Response() res: any) {
      const parts = await this.partsService.findAll();
      return res.status(HttpStatus.OK).json(parts);
    }
  }
  </code></pre>
  
  <p>And this is unit test which must test getParts method:</p>
  
  <pre><code>describe('PartsController', () =&gt; {
    let partsController: PartsController;
    let partsService: partsService;
  
    beforeEach(async () =&gt; {
      partsService = new partsService(Part);
      partsController= new PartsController(partsService);
    });
  
    describe('findAll', () =&gt; {
      it('should return an array of parts', async () =&gt; {
        const result = [{ name: 'TestPart' }] as Part[];
  
        jest.spyOn(partsService, 'findAll').mockImplementation(async () =&gt; result);
  
        const response = {
          json: (body?: any) =&gt; {
            expect(body).toBe(result);
          },
          status: (code: number) =&gt; response,
        };
  
        await partsController.getParts(response);
      });
    });
  });
  </code></pre>
  
  <p>This test works correctly, but I think this is a bad solution. When I investigated this problem, I saw this option:</p>
  
  <pre><code>const response = {
    json: (body?: any) =&gt; {},
    status: (code: number) =&gt; response,
  };
  expect(await partsController.getParts(response)).toBe(result);
  </code></pre>
  
  <p>But when I try it my test don't work, cause   await partsController.getParts(response) // undefined
  So what should I do to make my test look good?</p>
  
  <p>In solution I use: nodeJS sequelize, nestJS, typescript</p>