[英]Promise.then is not executing in Jasmine
JavaScript-Jasmine測試框架問題
嗨,大家好,由於某些原因,helpers.getWeatherData返回了一個承諾,但是我無法使用.then來解決它。
在這方面也找不到太多的文檔。
幫助將是驚人的!
import Jasmine from 'jasmine'
const jasmine = new Jasmine()
jasmine.loadConfigFile('spec/support/jasmine.json')
import helpers from '../src/lib/helpers'
import fetch from 'node-fetch'
import Promise from 'bluebird'
describe("Weather Service App", function() {
const URL = `http://api.openweathermap.org/data/2.5/forecast?`;
beforeEach(function(){
console.log('hello')
helpers.getWeatherData(URL).then((arr)=>{
console.log(arr.length, 'length')
})
})
console.log(helpers.getWeatherData(URL))
it("Test API endpoint, return array of five objects", function() {
});
});
jasmine.execute()
問題可能是在beforeEach
操作時, beforeEach
需要作為參數done
。
它將運行beforeEach函數,而無需等待promise完全執行。
要解決此問題,您可以嘗試以下操作:
beforeEach(function(done) {
console.log('hello');
helpers.getWeatherData(URL).then((arr) => {
console.log(arr.length, 'length');
done();
})
})
參見https://jasmine.github.io/2.4/introduction.html#section-Asynchronous_Support
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.