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

145
Views
¿Devolver un valor de un bloque asíncrono en Cypress?

Estoy tratando de devolver un valor de una función donde el valor devuelto está dentro del bloque then(). Cypress arroja un montón de errores de que estoy mezclando código asíncrono y sincronizado. Intenté devolver una Promesa y resolverla, pero eso también arrojó errores.

 cy.get('.btn.btn-primary') .each(function ($el, index, $list) { // Lot of code if (price < minPrice) minPrice = price }) .then(() => { cy.log(minPrice); //This works fine return minPrice; //This throws ERROR })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar un alias para guardar el valor y luego usarlo de esta manera.

 cy.get('.btn.btn-primary') .each(function ($el, index, $list) { // Lot of code if (price < minPrice) minPrice = price }) .then(() => { cy.log(minPrice) //This works fine cy.wrap(minPrice).as('minPrice') //Saved as alias }) //In your test you can use it as cy.get('@minPrice').then((minPrice) => { //Access minPrice here cy.log(minPrice) //prints minPrice })
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!