Reputation: 46760
I have this snippet of code in a directive
var modalPromise = $modal({template: '/Templates/Alerts/Upsell.html', persist: true, show: false, backdrop: 'static', scope: scope});
$q.when(modalPromise).then(function(modalEl) {
modalEl.modal('show');
});
In my Jasmine test I want to assert that the show
method is called, so I have this
...
.service('modal', function () {
var $modal = jasmine.createSpyObj('$modal', ['show']);
return $modal;
})
...
expect($modal('show')).toHaveBeenCalled();
But this gives me the error Cannot read property 'protocol' of undefined.
I think I am doing something wrong here. How do I assert that this line is being called?
Upvotes: 0
Views: 137
Reputation: 50265
A plunker or fiddle would have helped here but here is my assumption. After spying the $modal
for show
you also have to call andCallThrough()
to allow all subsequent calls to be delegated to actual implementation of $modal
. Like:
.service('modal', function () {
var modal;
spyOn(modal, 'show').andCallThrough();
return modal;
})
Upvotes: 1