Asynchronous 如何在Cumber测试中测试承诺的返回值?
我试图测试get请求对couchdb节点的返回值 我有一个使用以下给定条款定义的功能:Asynchronous 如何在Cumber测试中测试承诺的返回值?,asynchronous,cucumber,couchdb,axios,cucumberjs,Asynchronous,Cucumber,Couchdb,Axios,Cucumberjs,我试图测试get请求对couchdb节点的返回值 我有一个使用以下给定条款定义的功能: Given A get request is made to the DB 通过以下步骤功能实现: var Profile = require('../UserProfile.js') Given('A get request is made to the DB', function () { var text = Profile.getDB('localhost:5984').then(data
Given A get request is made to the DB
通过以下步骤功能实现:
var Profile = require('../UserProfile.js')
Given('A get request is made to the DB', function () {
var text = Profile.getDB('localhost:5984').then(data => {
console.log(data)
})
});
上述步骤引用了此模型:
var axios = require('axios')
module.exports = {
getDB: function(url){
return axios.get(url).then(response => {
return response.data
})
}
};
当我在模型中执行GET请求并在步骤定义中引用它时,我似乎无法记录GET请求的结果。当我在步骤定义中执行GET请求时,它是有效的——但这对我没有用处,我想测试模型。如何获取结果值?,请尝试:
const Profile = require('../UserProfile')
const { defineSupportCode } = require('cucumber')
defineSupportCode(({ defineStep }) => {
defineStep('A get request is made to the DB', function () {
return Profile.getDB('http://localhost:5984').then(data => {
console.log(data)
})
})
})