jeudi 28 avril 2016

Using $httpBackend to test directives and its expecting a bunch of templates in addition to my directive template

Based upon what I've read I should be able to just give it a link to the template for the directive and it should work, like so:

describe('Directive: ordercloudCatalogSearch', function() {
    var element;
    var http;
    beforeEach(inject(function($compile, $httpBackend) {
        http = $httpBackend;
        http.expectGET('catalogSearch/templates/catalogSearchDirective.tpl.html').respond();
        element = $compile('<ordercloud-catalog-search maxprods="8" maxcats="8"></ordercloud-catalog-search>')(scope);
        scope.$digest();
    }));
    fit('should initialize the isolate scope', function() {
        http.flush();
        console.log('isolated scope:', element.isolateScope());
        expect(element.isolateScope().maxprods).toBe('8');
        expect(element.isolateScope().maxcats).toBe('8');
    });
});

The following test runs successfully but asks for 5 additional templates! There has to be a better way?

describe('Directive: ordercloudCatalogSearch', function() {
    var element;
    var http;
    beforeEach(inject(function($compile, $httpBackend) {
        http = $httpBackend;
        http.expectGET('catalogSearch/templates/catalogSearchDirective.tpl.html').respond();
    http.expectGET('http://ift.tt/1rkVGxb').respond();
        http.expectGET('base/templates/base.tpl.html').respond();
        http.expectGET('base/templates/base.top.tpl.html').respond();
         http.expectGET('base/templates/base.left.tpl.html').respond();
        http.expectGET('home/templates/home.tpl.html').respond();
        element = $compile('<ordercloud-catalog-search maxprods="8" maxcats="8"></ordercloud-catalog-search>')(scope);
        scope.$digest();
    }));
    fit('should initialize the isolate scope', function() {
        http.flush();
        console.log('isolated scope:', element.isolateScope());
        expect(element.isolateScope().maxprods).toBe('8');
        expect(element.isolateScope().maxcats).toBe('8');
    });
});
});

Aucun commentaire:

Enregistrer un commentaire