Jasmine tests AngularJS Directives with templateUrl

前端 未结 8 702
执笔经年
执笔经年 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:46

    If you are using the jasmine-maven-plugin together with RequireJS you can use the text plugin to load the template content into a variable and then put it in the template cache.

    
    define(['angular', 'text!path/to/template.html', 'angular-route', 'angular-mocks'], function(ng, directiveTemplate) {
        "use strict";
    
        describe('Directive TestSuite', function () {
    
            beforeEach(inject(function( $templateCache) {
                $templateCache.put("path/to/template.html", directiveTemplate);
            }));
    
        });
    });
    

提交回复
热议问题