Jasmine testing service that handle callback functions
<p>I've created a service, that store callback functions. When angular resize and/or orientation-change event occured the stored callback will be called.</p>

<p>I would like to write some test in Jasmine for this service.
There is an <strong><em>addCallback</em></strong> method. This store the callback functions. I created this test case, but i don't know how to check the 'print2' function is called.</p>

<pre><code>describe('Testing Resize-updater service',function(){

var resizeUpdater;
var $window;
beforeEach(module('app.services'));
beforeEach(inject(function(_resizeUpdater_,_$window_){
    resizeUpdater = _resizeUpdater_;
    $window = _$window_;
}));

describe('Add a Callback and resize event',function(){

    var change;

    it('Test 1',inject(function(){
        var $timeout = _$timeout_;

        $window.innerWidth = 1368;
        $window.innerHeight = 768;
        function print2(){
            change = "called"
        }
        resizeUpdater.addCallback(print2);
        $window.innerWidth = 1300;      //this trigger resize event
        expect(change).toBe("called");

    }));
});
});
</code></pre>

<p>And here is the full service code:</p>

<pre><code>(function() {
'use strict';

angular
    .module('app.services')
    .factory('resizeUpdater', ['$window','$q','$timeout','$log',UpdaterService ]);

function UpdaterService($window, $q, $timeout, $log){

var api = {};

var size = {
    width: undefined,
    height: undefined,
    orientation: undefined
};


api.getSize = function(){
    size.width = $window.innerWidth;
    size.height = $window.innerHeight;
    size.orientation = (function(){
        if (size.width &gt;= size.height){
            return "landscape";
        } else {
            return "portrait";
        }
    })();
    return size;
};

api.list = [];

api.addCallback = function(callback) {
    api.list.push(callback);
};

api.removeCallback = function(callback){
    var index = api.list.indexOf(callback);
    delete api.list[index];
};

/*private method*/
var runAll = function() {

    for(var item in api.list){
        var obj = new Obj(api.list[item]);
        obj.execute();
    }

};

function Obj(callback) {
    this.promise = undefined;
    this.callback = callback;
    this.execute = function () {
        var defer = $q.defer();
        this.callback(function (response) {
            if (response === 'error') {
                defer.reject('Error occured.');
                $log.error('Failed - '+ callback.name + ' - ' + (new Date).toString());
            } else {
                defer.resolve(response);
            }
        });

        this.promise = defer.promise;
        this.promise.then(function(result){
            $log.log('Executed - '+ callback.name + ' - ' + (new Date).toString());
        });
    };
}

angular.element($window).on('resize',(function(){
    var timer_promise;
    return function(){
        if (timer_promise) {
            $timeout.cancel(timer_promise);
        }
        timer_promise = $timeout(function(){
            runAll();
        }, 500);
    };

})());

return api;

}})();
</code></pre>