lundi 4 juillet 2016

Testing function with form as argument in angularjs with karma and jasmine

I am using Angularjs+grunt+karma+jasmine. This is how I have wrote the function in my controller:

Vm.find = function(form){
 /* code lines */
};

and I have called the function with ng-click on the view side.

<form name="form">
<input/>
<input/>
<input/>
<button ng-click(Vm.find(form))></button>
</form>

Now I am struck on how to call the function with the form as argument in the unit testing. I am using the below code in the testing spec file to fetch the template html. But don't know how to trigger the function.

html = templateCacheMock.get('modules/reports/partials/renewals/generate-renewals.htm');
    complied = angular.element(html);
    element = compileMock(complied)(scope);
    element.find('.find-btn').triggerHandler('click');

Someone please guide me on this please. I am totally new to unit testing.

Aucun commentaire:

Enregistrer un commentaire