"it" in mocha does not run on using await.
I use functions to read files asynchronously and based on the returned value, run multiple loops to process my test. I also use the same file read functions multiple times in the loop. I need to use await to get the resolved value from that function. If I remove the await then the "it" runs but my function remains unresolved.
const subList1 = [
{name: 'value1', info: 'value1'},
{name: 'value2', info: 'value2'},
{name: 'value3', info: 'value3'},
]
const subList2 = [
{name: 'value1', info: 'value1'},
{name: 'value2', info: 'value2'},
{name: 'value3', info: 'value3'},
]
const subList3 = [
{name: 'value1', info: 'value1'},
{name: 'value2', info: 'value2'},
{name: 'value3', info: 'value3'},
]
const mainList = [
subList1, subList2, subList3,
]
function getList() {
return mainList;
}
describe('Test', async function () {
const list = await getList();
list.forEach(mainListItem => {
describe('Main Test', function () {
mainListItem.forEach(subListItem => {
describe(subListItem.name, function () {
let valueInCaps;
const name = subListItem.name;
console.log(`name: ${JSON.stringify(name)}`);
before(function () {
valueInCaps = subListItem.info.toUpperCase();
})
it(name, function () {
console.log(valueInCaps);
})
})
})
});
});
})
Expected:
name: "value1"
name: "value2"
name: "value3"
name: "value1"
name: "value2"
name: "value3"
name: "value1"
name: "value2"
name: "value3"
Test
Main Test
value1
VALUE1
√ value1
value2
VALUE2
√ value2
value3
VALUE3
√ value3
Main Test
value1
VALUE1
√ value1
value2
VALUE2
√ value2
value3
VALUE3
√ value3
Main Test
value1
VALUE1
√ value1
value2
VALUE2
√ value2
value3
VALUE3
√ value3
Actual:
name: "value1" name: "value2" name: "value3" name: "value1" name: "value2" name: "value3" name: "value1" name: "value2" name: "value3"
Aucun commentaire:
Enregistrer un commentaire