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

843
Views
Las funciones de prueba no pueden tomar una devolución de llamada 'hecha'

Estoy tratando de crear una prueba simple con nestjs y recibo este error

Las funciones de prueba no pueden tomar una devolución de llamada 'hecha' y devolver algo. Utilice una devolución de llamada 'hecha' o devuelva una promesa.

Valor devuelto: Promesa {}

La prueba unitaria es muy simple, pero recibo un error cuando uso done();

 it('throws an error if user signs up with email that is in use', async (done) => { fakeUsersService.find = () => Promise.resolve([{ id: 1, email: 'a', password: '1' } as User]); try { await service.signup('asdf@asdf.com', 'asdf'); } catch (err) { done(); } });
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Estás combinando Async/Await y Listo.

O use asnyc/await, o listo.

 it('throws an error if user signs up with email that is in use', async () => { try { await service(); expect(...); } catch (err) { } });

o usa el formato hecho

 it('throws an error if user signs up with email that is in use', (done) => { ... service() .then( ...) {} .catch( ...) {} } done(); });
over 4 years ago · Santiago Trujillo Report

0

para la última versión de jest, no puede usar `async/await, prometer y hacer juntos.

la solucion es

 it("throws an error if user sings up with email that is in use", async () => { fakeUsersService.find = () => Promise.resolve([{ id: 1, email: "a", password: "1" } as User]); await expect(service.signup("asdf@asdf.com", "asdf")).rejects.toThrow( BadRequestException ); });

cambie BadRequestException de acuerdo con su excepción de escucha

over 4 years ago · Santiago Trujillo Report

0

Además, si desea usar ambos, puede degradar su versión actual de broma a: 26.6.3. Funcionó bien para mí, estoy usando async + done

over 4 years ago · Santiago Trujillo 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!