一段时间以来,我一直在努力让这个测试通过。我希望它返回一个包含 3 个 mockExpectedResult 对象的数组
步骤1:减少计划操作数组(省略没有路径的项目)。这应该返回 InventoryItemPath 的字符串数组
第 2 步:减少 InventoryItemPath 数组 (freeRewardsInventory),对服务进行异步调用(getItem 是此异步 GET 请求的模拟),该服务返回 Promise。
第 3 步:通过 freeRewardsRaw Promises 进行缩减,格式化为 mockExpectedResult
步骤 4:返回输出(mockExpectedResults 数组)
我认为我的主要问题是我没有等待所有这些承诺(也许错过了一个等待?)
谢谢你的帮助。
const mockScheduledOperation = {
Ranks: [{
FreeRewards: {
InventoryRewards: [{
InventoryItemPath: 'Inventory/Armor/Visors/012-001-reach-c09fa0b7.json',
}, ],
},
},
{
FreeRewards: {
InventoryRewards: [{
InventoryItemPath: 'Inventory/Armor/Visors/012-001-reach-c09fa0b7.json',
}, ],
},
},
{
FreeRewards: {
InventoryRewards: [{
InventoryItemPath: 'Inventory/Armor/Visors/012-001-reach-c09fa0b7.json',
}, ],
},
}
]
};
const getAllRewards = async () => {
const freeRewardsInventory = mockScheduledOperation.Ranks.reduce(
(agg, rank) => {
if (rank.FreeRewards.InventoryRewards.length > 0) {
const rewardList = rank.FreeRewards.InventoryRewards.reduce(
(agg, reward) => {
if (reward.InventoryItemPath) {
agg = reward.InventoryItemPath;
}
return agg;
},
''
);
agg.push(rewardList);
}
return agg;
},
[]
);
const getItem = async (rewardPath: string) => mockReturnedItem;
const freeRewardsRaw = freeRewardsInventory.reduce < [] > (
async (agg, rewardPath) => {
const promise = await getItem(rewardPath);
agg.push(promise);
return agg;
},
[]
);
梵蒂冈之花
相关分类