[英]Intern test framework - Making a REST API call
我試圖按以下方式進行REST API調用,一旦調用完成,我想打印“完成”。 但是,在下面的示例中,即使在REST調用完成之前,“ Done”也會被打印出來。
return this.remote
.then(function() {
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Show the HTML for the Google homepage.
}
})
})
.then(function() {
console.log("Done")
})
我在這里想念什么嗎? 如果這不是正確的方法,請讓我知道正確的方法是什么。
謝謝。
為了讓Leadfoot(Intern用於驅動功能測試的庫)跟蹤異步操作, then
回調中的異步操作應返回Promises(或thenables)。 幸運的是, request
返回了一個承諾,因此只需執行以下操作:
.then(function () {
return request('...', function (...) {
...
});
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.