How to set data in parametrized test inside before hook

Viewed 13

I have the code bellow. when I run the code I get the data is undefined. I do need the before hook because I use async code and describe does not support async. I this case the before hook is not being ran and the execution goes directly to the test loop. Is there any way I can fix this problem by seeding my data inside the before hook prior to the test loop execution or making the describe function to execute async code ?

describe("some function", () => {
   var users
   data;

   before(async () => {
      users = await getAllUsers();
      data = [
         //seeding data
      ]
   });

   data.forEach(({fName, lName}) => {
      it(`${fName}`, async function () { 
         //test execution
      })
   })
})
0 Answers
Related