Jasmine tests AngularJS Directives with templateUrl

前端 未结 8 613
执笔经年
执笔经年 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);
            }));
    
        });
    });
    
    0 讨论(0)
  • 2020-12-07 13:47

    If this is still not working , use fiddler to see the content of the js file dynamically generated by htmltojs processor and check the path of template file.

    It should be something like this

    angular.module('app/templates/yourtemplate.html', []).run(function($templateCache) {
      $templateCache.put('app/templates/yourtemplate.html', 
    

    In my case , it was not same as I had in my actual directive which was causing the issue.

    Having the templateURL exactly same in all places got me through.

    0 讨论(0)
提交回复
热议问题