Currently, I am experimenting with a directive where I am incorporating the Mobiscroll library. Despite being aware of Mobiscroll's angular components, I am opting to work with older versions of the library for now.
The challenge I am facing involves testing whether a specific method on an element is being called, specifically the mobiscroll method. Below is the snippet of code from the link method of my directive:
link: function (scope, element, attr) {
var datepicker = element.find("input");
scope.showDate = function () {
datepicker.mobiscroll('show');
};
}
In Jasmine tests, I aim to verify if datepicker.mobiscroll('show')
is indeed invoked. However, setting a spy on the element within the tests proves difficult as the element obtained through lookup will not be identical to the one utilized in my directive's link method. The following approach does not yield the desired results:
targetElement = $compile(elementBluePrint)($scope);
rootScope.$apply();
var target = targetElement.find("input");
spyOn(target, "mobiscroll").and.callThrough();
Given the limitations of the above method, how can I effectively spy on the mobiscroll method during Angular Jasmine tests?