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

138
Views
Writing a test case for a condition where the data is an array that generates many data using a function

This is the function that is in the mockData folder


export const generateNotificationMockMany = (count) => (
    [...new Array(count)].map((index) => ({
            'group': `group number ${index}`,
            'message': `msg for group number ${index}`,
            'datetime': '',
        }),
    ));




this is the test case I've been trying to write. the data is being imported from a file that has this function in it that generates the mockdata. How can I write the test case for it? basically how can I use a loop to be able to get access to all the generated data by the function?

it('renders properly for the many variant', ()=> {
        render(<NotificationMenu notifications={notificationsMock}/>)

    });

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

0

Does one of the following options solve your problem, or do you expect something else ?

loop over test cases:

const mocks = generateNotificationMockMany(10);

for (let notificationsMock of mocks) {
  it(`renders properly for the variant ${notificationsMock}`, ()=> {
    render(<NotificationMenu notifications={notificationsMock}/>)
  });
}

loop inside test case:

const mocks = generateNotificationMockMany(10);

it(`renders properly for the many variant`, ()=> {
  for (let notificationsMock of mocks) {
    render(<NotificationMenu notifications={notificationsMock}/>)
  }
});
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!