Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
¿Cómo crear una prueba para el siguiente controlador?

¿Necesito escribir una prueba para el siguiente código?

 @Post() update(@Body() updateUserDto: UpdateUserDto, @Request() req) { return this.userService.update(req.user.user, updateUserDto); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Voy a hacer algunas suposiciones sobre las propiedades inyectadas de la clase de controlador. Para configuraciones completas, puede ver mi repositorio de ejemplo de prueba aquí . Sin embargo, esto debería ser esencialmente lo que estás buscando.

 describe('UserController (Unit)', () => { let controller: UserController; let service: MockedClass<UserService>; beforeAll(async () => { const modRef = await Test.createTestingModule({ controllers: [UserController], providers: [ { provide: UserService, useValue: { update: jest.fn().mockReturnValue({ hello: 'world' }), }, } ], }).compile(); controller = modRef.get(UserController); service = modRef.get(UserService); }); it('should call update and return the value', () => { const bodyVal = objectThatMatchesUpdateUserDto; const reqVal = { user: { user: valueThatMatchesReqUserUser } }; const res = controller.update(bodyVal, reqVal); expect(res).toEqual({ hello: 'world' }); expect(service.update).toBeCalledWith(reqVal.user.user, bodyVal) }); });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!