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

290
Views
Cypress: no puede leer las propiedades de undefined

Tengo tal problema que Cypress no puede encontrar las propiedades. En respuesta obtengo array. Quiero encontrar el registro y obtener CustomMessage. :) ¿Te das cuenta de dónde estoy cometiendo un error: /? respuesta de la consola

error de ciprés

Aquí está mi código :)

 cy.request({ method: 'GET', url: 'url', }) .then((resp) => resp.body) .then((data) => data.find((element) => element['body']['Message']['Phone'] == phone) ) .then((phone) => (otpCode = phone['body']['Message']['CustomMessage']))

Gracias por cualquier ayuda :)

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

0

El problema es que nada en la matriz coincide con el phone

Intenta agregar un guardia

 cy.request(...) .then((resp) => resp.body) .then((data) => { const found = data.find((element) => element.body.Message.Phone === phone) if (!found) throw 'Error: phone not found' return found }) .then((phone) => { otpCode = phone.body.Message.CustomMessage })

La forma en que lo tiene originalmente, cuando data.find() falla, toda la matriz se pasa a la extracción de otpCode .

about 4 years ago · Juan Pablo Isaza Report

0

Puede obtener el mensaje personalizado de esta manera:

 cy.request({ method: 'GET', url: 'url', }).then((resp) => { const customMessage = resp.body[1].body.Message.customMessage })
about 4 years ago · Juan Pablo Isaza Report

0

Hágalo simple con cy-spok .

 const 'spok' = require('cy-spok') cy.request({ method: 'GET', url: 'url', }) // access properties with .its() .its('response.body') .its(1) .should(spok({ Message: { Phone: spok.string // or us spok.test to check string length as well } // now we verified the response has Message.Phone let's extract it .its('Message.Phone') .as('otpCode')
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!