angularjs - How to unit test of a function which are inside another one -


for unit testing use jasmine.i want test filterlist function . how ? problem mock service object, how declare method inside mock object can test filterlist function.

ignore syntax , because copy paste code , delete lines, chances high there lots of syntax error.

function (_,angular) {     'use strict';     var ngdependencies = ['stateservice','$scope','$rootscope'];     var constructor = function constructor(stateservice,$scope,$rootscope) {         var self = this;         self.defaultselectedcompany = {};          self.companies = {             available: []         };          var changelistener = stateservice.subscribe(function () {             self.companies.available = stateservice.getavailable('clients');              self.mycompanylist = _.map(self.companies.available, function companylist(user) {                 return {                     id: user.name};             });      self.filterlist = function filterlist($searchval, $list) {             return _.filter($list, function (item) {                 return item.displayvalue.tolowercase().indexof($searchval.tolowercase()) >= 0 ||                     item.secondaryvalue.tolowercase().indexof($searchval.tolowercase()) >= 0;             });         };             self.updatedefaultcompany(self.mycompanylist[0]);         });          self.updatedefaultcompany = function updatedefaultcompanypreference(selected) {             self.defaultselectedcompany = selected;         };          $scope.$on('$destroy', changelistener);     };     constructor.$inject = ngdependencies;     return constructor; 

and spec files bellow

  function (angular, _) {     'use strict';           var mockstateservice = {             name: 'globalstateservice',             subscribe: jasmine.createspy('subscribe').and.callfake(function subscribe(state){              return {              filterlist : function filterlist($searchval, $list) {               return _.filter($list, function (item) {                 return item.displayvalue.tolowercase().indexof($searchval.tolowercase()) >= 0 ||                    item.secondaryvalue.tolowercase().indexof($searchval.tolowercase()) >= 0;                 });                }               };              })         };     describe('controller', function () {         beforeeach(function () {             module(module.name);             utils.usemocks([                 mockstateservice             ]);         });         beforeeach(inject(function ($controller, $rootscope) {             this.scope = $rootscope.$new();             this.reqdrawerctrl = $controller('settingscontroller', {$scope: this.scope});         }));         describe('filterlist', function () {             it('is function', function () {                 expect(typeof this.reqdrawerctrl.filterlist).tobe('function');             });         });     }); 


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -