For some reason, PhantomJS does not have a click () function in it. Here is a workaround:
function click(el){
var ev = document.createEvent('MouseEvent');
ev.initMouseEvent(
'click',
true , true ,
window, null,
0, 0, 0, 0,
false, false, false, false,
0 , null
);
el.dispatchEvent(ev);
}
And here is how to use it:
it('Should set the month when the month is changed', function(){
var obj = element[0].getElementsByClassName('month_opt')[1];
click(obj);
expect(scope.dt.getMonth()).toEqual(1);
});
source
share