Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
Javascript Karma单元测试尝试向完全不同的模块发送请求_Javascript_Angularjs_Jasmine_Karma Runner_Angular Fullstack - Fatal编程技术网

Javascript Karma单元测试尝试向完全不同的模块发送请求

Javascript Karma单元测试尝试向完全不同的模块发送请求,javascript,angularjs,jasmine,karma-runner,angular-fullstack,Javascript,Angularjs,Jasmine,Karma Runner,Angular Fullstack,我对角形全堆叠脚手架进行了以下业力测试: describe('Directive: categoryLookAhead', function () { // load the directive's module and view beforeEach(module('portfolioApp')); beforeEach(module('app/article/Directives/categoryLookAhead/categoryLookAhead.html')); v

我对角形全堆叠脚手架进行了以下业力测试:

describe('Directive: categoryLookAhead', function () {

  // load the directive's module and view
  beforeEach(module('portfolioApp'));
  beforeEach(module('app/article/Directives/categoryLookAhead/categoryLookAhead.html'));

  var element, scope;

  beforeEach(inject(function ($rootScope) {
    scope = $rootScope.$new();
  }));

  it('should make hidden element visible', inject(function ($compile) {
    element = angular.element('<category-look-ahead></category-look-ahead>');
    element = $compile(element)(scope);
    scope.$apply();
    expect(element.text()).not.toBe(null);
  }));
});
这是指令的控制器:

angular.module('portfolioApp')
  .directive('categoryLookAhead', function($interval, $filter) {
    return {
      templateUrl: 'app/article/Directives/categoryLookAhead/categoryLookAhead.html',
      restrict: 'E',
      scope: {
        suggestedTags: '=',
        selectedTags: '='
      },
...
在我看来,它应该从该模板编译并开始做它的事情,但我得到了一个错误:

错误:意外请求:获取app/main/main.html

main.html根本不包含这个指令,所以我不知道为什么它会收到一个意外的请求


我在其他StackOverflow帖子中读到,我可以使用whenGET(*).passThrough()忽略这些事情,但我想知道为什么它会向与指令无关的模块发出请求。

如果模板使用
ng include
。运行
方法(或者其他任何方法,真的)请求此模板您将遇到此问题。对视图和控制器进行了快速检查,但没有ng include或。run。我在每个模块(模块('portfolioApp')之前包含整个应用程序
那么想知道这是否会影响它吗?我的意思是
ng include
。run
可以在
portfolioApp
中的任何位置。似乎在初始化模块时,
app/main/main.html
被加载。你在做任何类型的路由吗?如果这工作正常,并且在测试中失败了,也许你应该发布你的karma配置文件。哦,我明白了。我在几乎所有的页脚和导航栏视图中都使用了ng include。我的客户端/app/app.js中有一个.run。如果模板使用
ng include
.run
方法(或其他任何方法)请求此模板,我将使用我的karma.conf.js进行更新。您将遇到此问题。对视图和控制器进行了快速检查,但没有使用ng include或.run。我在每个模块(模块('portfolioApp')之前包含整个应用程序
那么想知道这是否会影响它吗?我的意思是
ng include
。run
可以在
portfolioApp
中的任何位置。似乎在初始化模块时,
app/main/main.html
被加载。你在做任何类型的路由吗?如果这工作正常,并且在测试中失败了,也许你应该发布你的karma配置文件。哦,我明白了。我在几乎所有的页脚和导航栏视图中都使用了ng include。我的客户端/app/app.js中有一个.run。我将使用karma.conf.js更新
angular.module('portfolioApp')
  .directive('categoryLookAhead', function($interval, $filter) {
    return {
      templateUrl: 'app/article/Directives/categoryLookAhead/categoryLookAhead.html',
      restrict: 'E',
      scope: {
        suggestedTags: '=',
        selectedTags: '='
      },
...