```ts cy.document().then((doc) => { const p...
# help
n
Copy code
ts
 cy.document().then((doc) => {
      const paragraph = doc.querySelector(nthParagraph(n))
      if (!paragraph) return
      return docs.find(doc => doc._id == paragraph.id)
  })
b
Are you expecting a paragraph htmlElement to return from your doc.querySelector?
n
yeah, it returns ok but idk how to return the result from the function
because this function is a helper function
Copy code
ts
export const findNthParagraph = (docs:any[],n:number) => {

    cy.document().then((doc) => {
      const paragraph = doc.querySelector(nthParagraph(n))
      if (!paragraph) return
      const data = docs.find(doc => doc._id == paragraph.id)
      return data
  }).then((a,b) => {
    
    })



}
it should return the nthParagraph
but since it's wrapped in the cy.document() call it doesn't return anything
@User
i
@User Did you try wrapping the data instead of returning it
so instead of return data
do
cy.wrap(data).as("someData")
n
Yeah just figured that out!
Copy code
ts
Cypress.Commands.add("getNthParagraphDBEntry",(docs:any[],n:number) => {
  cy.getNthParagraph(n).then(elem => {
    if (!elem) return
    const data = docs.find(doc => doc._id == elem[0].id)
    return cy.wrap(data).as("data")
  })
  return cy.get("@data")
})
The problem im having now is mapping commands across an array
Copy code
ts
  cy.wrap(children).each(elem => cy.getNthParagraphID(elem)).then(rs => {
    console.log(rs)
  })
2 Views