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

212
Views
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 answers
Answer question

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 Report

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 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!