【发布时间】:2019-05-22 03:23:26
【问题描述】:
关于在其中使用 await 的报告中跳过了第二级描述。
我有一个测试结构,我在测试中以多个级别异步读取文件并使用数据进行验证。
这是我的代码的过度简化版本,请原谅。 这个想法是在测试中进行多个异步调用以读取多个级别的文件。
const { expect } = require('chai');
const subList1 = [
{ title: 'subList1_title1', value: '1' },
{ title: 'subList1_title2', value: '2' },
{ title: 'subList1_title3', value: '3' },
];
const subList2 = [
{ title: 'subList2_title1', value: '1' },
{ title: 'subList2_title2', value: '2' },
{ title: 'subList2_title3', value: '3' },
];
const masterList = [
{
title: 'subList1',
value() {
return subList1;
},
},
{
title: 'subList2',
value() {
return subList2;
},
},
];
function getMasterList() {
return masterList;
}
describe('All Tests', async function () {
let testMasterList = [];
testMasterList = await getMasterList();
testMasterList.forEach(function (item) {
describe(item.title, async function () {
const list = await item.value();
list.forEach(function (element) {
describe(element.title, function () {
it('Value should be a string', function () {
expect(element.value).to.be.a('string');
});
});
});
});
});
});
setTimeout(function () {
run();
}, 1000);
我使用带有 mocha 的 --delay 标志来运行测试。
如果我删除第二个await,那么所有描述都会打印在控制台中。
预期:
subList1
subList1_title1
✓ Value should be a string
subList1_title2
✓ Value should be a string
subList1_title3
✓ Value should be a string
subList2
subList2_title1
✓ Value should be a string
subList2_title2
✓ Value should be a string
subList2_title3
✓ Value should be a string
实际:
subList1_title1
✓ Value should be a string
subList1_title2
✓ Value should be a string
subList1_title3
✓ Value should be a string
subList2_title1
✓ Value should be a string
subList2_title2
✓ Value should be a string
subList2_title3
✓ Value should be a string
【问题讨论】:
标签: loops asynchronous async-await mocha.js