jquery - How to test for my callback function with Jasmine? -


i have angular service class : -

// loads user data firebase

this.init = function(readycallback) {   var log = angular.extend({}, this._log);   log.funct = 'init';    var fireref = new firebase('https://luminous-inferno-1740.firebaseio.com/' + $rootscope.clientname);   config = $firebase(fireref.child('config')).$asobject();   userstate = $firebase(fireref.child('userstate').child($rootscope.username)).$asobject();    promise.all([config.$loaded(), userstate.$loaded()]).     then(       function() {         if(config == null || object.keys(config).length < 4) {           log.message = 'invalid config';           $log.error(log);           return;         }          if(!userstate.userproperties) {           userstate.userproperties = {};         }          if(!userstate.contentproperties) {           userstate.contentproperties = {};         }           log.message = 'user properties: ' + json.stringify(userstate.userproperties);         $log.debug(log);          log.message = 'content properties: ' + json.stringify(userstate.contentproperties);         $log.debug(log);          log.message = 'loaded user data firebase';         $log.debug(log);         readycallback();       },       function() {         log.message = 'unable load user data firebase';         $log.error(log);       }     ); }; 

i trying unit test service using jasmine:-

my unit test :-

// load service's module    beforeeach(function() {     module('triggertips');   });  // instantiate service    var userdata;   var $firebase;   var log;   var $rootscope;   beforeeach(inject(function (_userdata_, _$rootscope_, $log, _$firebase_, $http) {     userdata = _userdata_;     $firebase=_$firebase_;     log = $log;     $rootscope = _$rootscope_;     $rootscope.clientname = 'testclient';     $rootscope.username = 'userdatatest';     $rootscope.usergroupname = 'testgroup';     $rootscope.env = 'dev';   }));    it('should load correctly', function () {     expect(!!userdata).tobe(true);   });     describe('initial configuration test user', function () {        beforeeach(function(done){           var config = {                 'apache 404' : {                   content : {                     type : 'tip',                     template : 'yesno',                     text : 'are searching status code 404?',                     yestext : 'try our more accurate <a href="https://www.loggly.com/docs/search-query-language/#field_names" target="_blank">field search</a>',                     attachto : '#inputbox right',                     yesactions : {                       0 : {                           type : 'replacesubstring',                           target : '#inputbox',                           value : 'apache.status:404',                           match : '404'                         }                     }                   },                   conditions : {                     0 : {                         type : 'valuechange',                         target : '#inputbox',                         textmatch : '(^|([\\s]+))404(([\\s]+)|$)',                         preventsubmit : true                       },                     1 : {                         type : 'contentpropertylessthan',                         propertyname : 'timesshown',                         compareval : 3                       }                   }                 }           };            var fireref = new firebase('https://luminous-inferno-1740.firebaseio.com/' + $rootscope.clientname);           var firesync = $firebase(fireref);           firesync.$set({'config' : config});            userdata.init();           jasmine.default_timeout_interval = 2000;       });        it('should have success log', function(done) {           settimeout(function() {               expect(log.debug.logs.length > 9).tobe(true);               expect(log.debug.logs.length).tobegreaterthan(2);               done();             }, 2500);       });        it('should have valid config', function () {           expect(object.keys(userdata.getconfig()).length == 1).tobe(true);       });   }); 

i new receiving error :

can me providing working example of code ?


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -