为什么此测试返回测试完成而不运行任何断言?诺言处理有问题吗?如果我在服务器上运行此代码,则一切正常。
test.serial('test with req' , async (assert) => {
var promise = new Promise(function(resolve, reject) {
request('https://www.random.org/integers/?num=1&min=1&max=100&col=5&base=10&format=plain&rnd=new',
(error, response, body) => {
console.log(response)
if(!error){
resolve(body)
} else {
reject(error)
}
})
})
promise.then((result) => {
console.log(result);
assert.true(result !== undefined)
}, (err) => {
console.log(err)
assert.true(err !== undefined)
})
})
答案 0 :(得分:0)
鉴于request
已经有了诺言支持,您可以使用async
/ await
test.serial('test with req' , async (assert) => {
const result = await request('https://www.random.org/integers/?num=1&min=1&max=100&col=5&base=10&format=plain&rnd=new');
assert.true(result !== undefined);
})