-1

I want to generate it() tests in a loop, but the data required to drive the loop needs to be retrieved asynchronously first. I've tried solving the problem using before() but it won't work. The code below retrieves and displays the parameters in the loop correctly but... the it() tests don't get executed. It's as if mocha ignores it() that appear AFTER waiting on a promise.

describe('Generated tests', async () => {
     const testParams = await <asynchronous call here>
     testParams.forEach(testParam=> {
        console.log(testParam)
        it(`Generated test for ${testParam}, () => myTestFunc(testParam))
      })
})
Ya.
  • 1,671
  • 4
  • 27
  • 53

1 Answers1

0

Solved this by placing await before describe:

describe('All Tests', async () => {
  it('Level1 Test', () => <test code here> )

  const testParams = await <async call here>
  describe('Generated tests', () => {
      testParams.forEach(testParam=> it(`Test ${testParam}`, ()=>testFunc(testParam))
   })
})
Ya.
  • 1,671
  • 4
  • 27
  • 53