$ionicPopup confirm jasmine mock

Hey everyone!!

I have a popup confirm dialog as follow:

$scope.showConfirm = function() {
var confirmPopup = $ionicPopup.confirm({
title: ‘Consume Ice Cream’,
template: ‘Are you sure you want to eat this ice cream?’
});

confirmPopup.then(function(res) {
if(res) {
console.log(‘You are sure’);
} else {
console.log(‘You are not sure’);
}
});
};

What is the proper way to mock this to test the confirm method call and the successful response??

Thanks!! :grin:

Mock the whole $ionicPopup-Service:

return an object with a key “confirm” -> there you can create and resolve a promise immediately

if you have complex code --> you should move this to an own function --> after that you can handle the calls with spyOn.

1 Like

Thanks!

You guide me through the light :sunglasses:

@cnpallares ,Hallo, if that work with you can you write here the basic code to test because i got an error “confirmPopup.then is not a function” , thanks