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

128
Views
Cómo probar la promesa antes de que se ejecute finalmente con JEST

Tengo una función como esta:

 let settings = { isRun: false } function testPromise(promise) { settings.isRun = true; return promise.finally(() => settings.isRun = false;) }

¿Cómo se puede probar isRun = true cuando se ejecuta testPromise antes de ejecutar finalmente la expresión? probé con

 it('should isRun true when testPromise running', async () => { expect(settings.isRun).toBeFalsy(); await testPromise(Promise.resolve('run')).then(() => { expect(settings.isRun).toBeTruthy(); } expect(settings.isRun).toBeFalsy();

Pero no funciona

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que puede ejecutar pero no esperar a que la promesa observe el cambio de valor intermitente que desea ver.

 it('should isRun true when testPromise running', () => { expect(settings.isRun).toBeFalsy(); const promise = testPromise(Promise.resolve('run')); // At this point, promise is not resolved yet, so the callback in finally has not executed yet. expect(settings.isRun).toBeTruthy(); // If you want to test it changed back to fasle promise.then(() => { expect(settings.isRun).toBeFalsy(); }); }
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!