위도와 경도 일부 개체를 얻으려면 노드 지오 코더 npm 패키지를 사용하려고합니다.반환 JavaScript 약속 약속 값을 거절했습니다
자바 스크립트 약속을 이해해 주시겠습니까? 여기
은 예시 코드 :import nodeGeocoder from 'node-geocoder'
function getLocation (str) {
// Selecting Google as provider
const geocoder = nodeGeocoder({
provider: 'google',
})
return geocoder.geocode(str)
.then(response => {
// I want to return latitude an longitude
return [response[0].latitude, response[0].longitude]
})
.catch(error => {
console.log(`Geocoder Error: ${ error }`)
})
}
export default getLocation
겠어요 - 나는이 테스트를 사용하려고 해요 때
import getLocation from './index'
test('Checking',() => {
expect(getLocation('29 champs elysée paris')).toEqual([48.8698679, 2.3072976])
})
난 그냥 약속 상태 {"fulfillmentValue": undefined, "isFulfilled": false, "isRejected": false, "rejectionReason": undefined}
를 얻을 :이 테스트 (농담 프레임 워크)입니다.
하지만 결과를 약속해야합니다. 내가 어떻게 해? 나는 시험 테스트를 위해
아직 도착하지 않은 결과는 반환 할 수 없습니다. 당신이 성취해야 할 약속을 기다리십시오. – Bergi