-1
我在理解承诺方面遇到了一些问题。您能否帮助我:如何获得承诺的结果?
我正在尝试使用node-geocoder库。
所以,这是一个函数,它应该返回Google地图上某个点的纬度和经度的数组。
import NodeGeocoder from 'node-geocoder'
export default function getLocation() {
const geocoder = NodeGeocoder({
provider: 'google',
})
const point = geocoder.geocode('29 champs elysée paris', (error, response) => {
return [response[0].latitude, response[0].longitude]
})
return point
}
上面的代码应该为这个测试是确定:
import getLocation from './index'
test('This is a test',() => {
expect(getLocation()).toEqual([48.8698679, 2.3072976])
})
测试失败,我收到以下错误信息:
Expected value to equal:
[48.8698679, 2.3072976]
Received:
{"fulfillmentValue": undefined, "isFulfilled": false, "isRejected": false, "rejectionReason": undefined}
如何打开尚未送达的包裹? Promise就像发货确认一样,只是您正在等待的东西的占位符。你所能做的就是用这件事,等待承诺兑现/包裹交付。 '然后()'你可以随心所欲地做任何事。 – Thomas