Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 为什么运行这个角度测试抛出;无法识别的表达式“;?_Angularjs_Unit Testing_Angularjs Directive - Fatal编程技术网

Angularjs 为什么运行这个角度测试抛出;无法识别的表达式“;?

Angularjs 为什么运行这个角度测试抛出;无法识别的表达式“;?,angularjs,unit-testing,angularjs-directive,Angularjs,Unit Testing,Angularjs Directive,我的指示是 angular.module('My.directives'). directive('documentIcon', function(MyService) { return { restrict: 'A', replace: true, scope: { aDocument: '=', user: '=' }, templateUrl: '/partials/documentIcon.html',

我的指示是

angular.module('My.directives').
 directive('documentIcon',
   function(MyService) {
  return {
    restrict: 'A',
    replace: true,
    scope: {
      aDocument: '=',
      user: '='
    },
    templateUrl: '/partials/documentIcon.html',
    link: function(scope, elem, attrs) {
      scope.alignBottom = 'alignBottom' in attrs;

        //business stuff 
        }
      };
    }
  };
});
我的html模板是这样的

<span
</span>

我刚刚为自己修复了一个类似于此的错误,所以我想我应该在这里发布我的发现,因为这是一个相对较新的问题

您正在使用这个包,现在发生的事情是,声明用于缓存模板的angular模块的代码被加载为模板,而不仅仅是HTML模板

这种情况发生在我身上的原因是,我无意中还在同一组文件上运行另一个预处理器。我建议您在karma.conf.js中查找类似的内容

preprocessors: {
  '**/*.html': 'html2js',
  // ... other preprocessors
  '**/*.html': 'ng-html2js'
},

您需要确保其中只有一个在您的模板上运行。

您在HTML中声明模块的位置?我正在使用grunt插件,该插件在测试时缓存模板,并使其作为模块可用。请显示更多代码。你在期待什么?
  Error: Syntax error, unrecognized expression: angular.module('/partials/documentIcon.html', []).run(function($templateCache) {
        $templateCache.put('/partials/documentIcon.html',
          '<span>\n' +
          '</span>');
      });
          at ......project/web/js/lib/jquery-1.11.0.min.js:2
          at ob (......project/web/js/lib/jquery-1.11.0.min.js:2)
          at xb (......project/web/js/lib/jquery-1.11.0.min.js:2)
          at db (......project/web/js/lib/jquery-1.11.0.min.js:2)
          at ......project/web/js/lib/jquery-1.11.0.min.js:2
          at ......project/web/js/lib/jquery-1.11.0.min.js:2
          at ......project/web/js/lib/jquery-1.11.0.min.js:2
          at removeComments (......bower_components/angular/angular.js:8352)
          at ......bower_components/angular/angular.js:7935
          at processQueue (......bower_components/angular/angular.js:13248)
          at ......bower_components/angular/angular.js:13264
          at ......bower_components/angular/angular.js:14466
          at ......bower_components/angular/angular.js:14282
          at ......bower_components/angular/angular.js:14571
          at /......test/helpers/angular-spec-helpers.js:28
          at invoke (......bower_components/angular/angular.js:4203)
          at workFn (......bower_components/angular-mocks/angular-mocks.js:2436)
          at ......bower_components/angular-mocks/angular-mocks.js:2408
          at /......test/helpers/angular-spec-helpers.js:29
          at /......test/unit/directives/documentIconSpec.js:31
      undefined
preprocessors: {
  '**/*.html': 'html2js',
  // ... other preprocessors
  '**/*.html': 'ng-html2js'
},