lundi 8 juin 2015

How to test existence of template in templateCache? [Karma-Jasmine-AngularJS]

In my JS, I have section of code as below:

var $raw_html = $templateCache.get(attr.sidePopupUrl);                
    if ($raw_html) {  // if the template exist in the cache, then continue with the popupElement function
            popupElement($raw_html);
    }else{ // if template not exist, fetch the template using $http and put the respond into template cache, then continue with the popupElement function

         $http.get(attr.sidePopupUrl).then(function(response) {
             var $raw_html = response.data;
             $templateCache.put(attr.sidePopupUrl, $raw_html);
             popupElement($raw_html);
         });

    }

In my test, I expect the test to be like this, but no idea how to write it:

describe('Popup template', function(){
        it("Should continue with the popupElement function if template exist in templateCache", function(){
                 // Anyone have ideas?
        });

});

describe('Popup template', function(){
        it("Should fetch from the server and put the retrieved response to the template cache if the template is not available in the cache, then continue the popupElement function", function(){
                // Anyone have ideas?
        });

});

Anyone could help?

Aucun commentaire:

Enregistrer un commentaire