I'm currently in the process of testing a function that takes a value from a promise, concatenates this value (which is a string) to a URL. The actual implementation of the function seems to be working perfectly fine.
var resp = {"payment": {
"additional_information": {
"skuSeatIds": "[{\"sku\":\"5234\",\"Description\":\"Advanced\",\"seatId\":792}]"
}}};
var promise = Promise.resolve(JSON.parse(resp.payment.additional_information.skuSeatIds));
var update = spyOn(doneService, 'getOrderInfo').and.returnValue(promise);
var url = controller.setSeatIdLink();
expect(url).toBe('http://localhost:4000/#!/search?type=Selector&seatId=792');
});
Next, I have the function that calls doneService.getOrderInfo()
function setSeatIdLink () {
doneService.getOrderInfo(store.get('orderId')).then(function(resp){
var stri = vm.modalSelectorUrl.concat(resp[0].seatId);
vm.modalSelectorUrl = stri;
return vm.modalSelectorUrl;
});
}
The variable vm.modalSelectorUrl successfully gets set with the URL. The spyOn method also returns the correct value. However, when I try to access the url using expect(url), it gives me undefined.
If I manually set the return value outside the scope of .then(), everything works as expected.
Any suggestions or thoughts on why this might be happening? Thank you!