Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
How to get map values by index when inside each loop in JavaScript?

I try to write tests in a clean way. I iterate through the rows (each of which shows info about attached file) of the table on the page and verify if each attached file has correct size:

   it('attaches many documents', () => {
     const fileSizes = ['17.19 KB', '12.06 KB', '67.75 KB']
     cy.get('input[type="file"]').attachFile([excelFilePath, docxFilePath, pdfFilePath])

   
     cy.get('div.table-body>.table-row').each(($el, index) => {
       expect($el.find('.col-upload-size')).to.contain.text(fileSizes[index])
     })
        
   })

But earlier in the code I have this map defined:

const fileSizesMap = new Map([
    ["excelFileSize", "17.19 KB"],
    ["docxFileSize", "12.06 KB"],
    ["pdfFileSize", "67.75 KB"]
]);

Can I somehow get rid of fileSizes list inside of the test and make use of fileSizesMap instead?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I understand you want to replace fileSizes with the values from your fileSizesMap:

const fileSizes = Array.from(fileSizesMap.values())
about 4 years ago · Juan Pablo Isaza Relatório

0

You could try to return an iterable for values and do your assertions:

const fileSizesMap = new Map([
    ["excelFileSize", "17.19 KB"],
    ["docxFileSize", "12.06 KB"],
    ["pdfFileSize", "67.75 KB"]
]);

it('attaches many documents', () => {
    cy.get('input[type="file"]').attachFile([excelFilePath, docxFilePath, pdfFilePath])
    for (const value of fileSizesMap.values()) {
        cy.get('div.table-body>.table-row').then(() => {
            expect($el.find('.col-upload-size')).to.contain.text(value)
        })
    }
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda