【问题标题】:function uses multiple asynchronous interfaces Promise MapSeries函数使用多个异步接口 Promise MapSeries
【发布时间】:2021-07-09 04:53:50
【问题描述】:
return Promise.mapSeries(_.times(lineCount(reader)), i => {
        let dbFilter = { RefNumber : i }
        return expectData.dbDataExpected(dbCollection, dbFilter)
            .then(() => {
                console.log("Data: ", expectData.dataDB)
            })
    })

以上代码来自黄瓜步骤定义! 当我运行测试时,我收到以下错误:

错误:函数使用多个异步接口:回调和承诺 使用回调接口:不返回承诺 使用 promise 接口:删除函数的最后一个参数

你知道我为什么会收到这个错误吗?

【问题讨论】:

  • 你正试图从一个承诺中返回一个承诺 (.then()),尝试在你的 .then 中返回一个值
  • 我用从 mongo 获取数据的函数 dbDataExpected 更新了描述!在这种情况下我应该如何处理?
  • 您可能应该在 .then 之外初始化一个变量,将 .then 中的数据设置为外部变量,然后在返回时返回该变量而不是返回 .then() .then() 你正在返回一个承诺,但是通过在外部设置变量,你正在返回你的数据。

标签: javascript node.js typescript promise cucumberjs


【解决方案1】:

在执行步骤定义时,如果您的参数多于场景中定义的参数,那么您将收到此错误。

等式

场景: 当用户创建“car1”和“car2”时

步骤定义:

When('the user creates {string} and {string}',function(p1:string, p2:string, p3:string){
...
})

【讨论】:

    猜你喜欢
    • 2020-02-18
    • 1970-01-01
    • 2021-02-15
    • 2020-08-13
    • 2021-06-28
    • 2017-01-15
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    相关资源
    最近更新 更多