Jasmine tests AngularJS Directives with templateUrl

前端 未结 8 723
执笔经年
执笔经年 2020-12-07 12:54

I\'m writing directive tests for AngularJS with Jasmine, and using templateUrl with them: https://gist.github.com/tanepiper/62bd10125e8408def5cc

However, when I run

8条回答
  •  醉酒成梦
    2020-12-07 13:40

    this is example how to test directive that use partial as a templateUrl

    describe('with directive', function(){
      var scope,
        compile,
        element;
    
      beforeEach(module('myApp'));//myApp module
    
      beforeEach(inject(function($rootScope, $compile, $templateCache){
       scope = $rootScope.$new();
       compile = $compile;
    
       $templateCache.put('view/url.html',
         '
    • {{ foo }}
    • ' + '
    • {{ bar }}
    • ' + '
    • {{ baz }}
    • ' + '
    '); scope.template = { url: 'view/url.html' }; scope.foo = 'foo'; scope.bar = 'bar'; scope.baz = 'baz'; scope.$digest(); element = compile(angular.element( '
    ' + '
    ' + '
    ' + '
    ' ))(scope); scope.$digest(); })); it('should copy scope parameters to ngInclude partial', function(){ var isolateScope = element.find('div').eq(0).scope(); expect(isolateScope.foo).toBeDefined(); expect(isolateScope.bar).toBeDefined(); expect(isolateScope.baz).toBeDefined(); }) });

提交回复
热议问题