const dataArray = [['Data 3', 'd3'], ['Data 4', 'd4']];
dataArray.forEach(row => {
describe('Test group using %s with tag %s', () =>
{
let groupData = [{'id':'01'},{'id':'02'}];
let groupTag = '';
let datafile = '';
switch(row[1])
{
case 'd3': groupData = [{'id':'31'},{'id':'32'}]; break;
case 'd4': groupData = [{'id':'41'},{'id':'42'}]; break;
}
datafile = row[0];
groupTag = row[1];
console.log('Beginning tests for '+groupTag+' using '+datafile+'\r\n groupData set to '+JSON.stringify(groupData[0])+' and '+JSON.stringify(groupData[1]));
groupData.forEach(num => test('Test case ${num} [tag:sandbox]', () =>
{
console.log(groupTag+' - Running test '+num.id);
expect(num.id).toBeDefined(); //example test
}));
});
});
This got the 'desired' result, defining all the tests first, then running them
console.log Beginning tests for d3 using Data 3 groupData set to {"id":"31"} and {"id":"32"} Beginning tests for d4 using Data 4 groupData set to {"id":"41"} and {"id":"42"} d3 - Running test 31 d3 - Running test 32 d4 - Running test 41 d4 - Running test 42
hat tip to the linked question Using jest's test.each vs. looping with forEach
and https://stackoverflow.com/users/3001761/jonrsharpe for his comment.