最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - function uses multiple asynchronous interfaces Promise MapSeries - Stack Overflow

programmeradmin1浏览0评论
return Promise.mapSeries(_.times(lineCount(reader)), i => {
        let dbFilter = { RefNumber : i }
        return expectData.dbDataExpected(dbCollection, dbFilter)
            .then(() => {
                console.log("Data: ", expectData.dataDB)
            })
    })

The above code is from cucumber step definition! WHen I run the test I receive the following error:

Error: function uses multiple asynchronous interfaces: callback and promise to use the callback interface: do not return a promise to use the promise interface: remove the last argument to the function

Do you have any idea why i got this error?

return Promise.mapSeries(_.times(lineCount(reader)), i => {
        let dbFilter = { RefNumber : i }
        return expectData.dbDataExpected(dbCollection, dbFilter)
            .then(() => {
                console.log("Data: ", expectData.dataDB)
            })
    })

The above code is from cucumber step definition! WHen I run the test I receive the following error:

Error: function uses multiple asynchronous interfaces: callback and promise to use the callback interface: do not return a promise to use the promise interface: remove the last argument to the function

Do you have any idea why i got this error?

Share Improve this question edited Apr 16, 2021 at 5:53 Raul_M asked Apr 14, 2021 at 6:39 Raul_MRaul_M 2911 gold badge3 silver badges12 bronze badges 3
  • You are trying to return a promise (.then()) from a promise, try returning a value in your .then – cyw Commented Apr 14, 2021 at 6:44
  • I updated the description with the function dbDataExpected which get data from mongo! how should I proceed in this case? – Raul_M Commented Apr 14, 2021 at 6:54
  • You should probably initialize a variable outside of your .then, set the data from the .then to the variable on the outside, then return that variable instead of returning the .then(), when you return the .then() you are returning a promise, but by setting the variable on the outside, you are returning your data. – cyw Commented Apr 14, 2021 at 7:06
Add a comment  | 

1 Answer 1

Reset to default 22

When implement a step definitions in case if you have more parameters than those defined in the scenario, then you will receive this Error.

Eq.

Scenario: When the user creates "car1" and "car2"

Step definition:

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

评论列表(0)

  1. 暂无评论