Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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_Angularjs Directive_Karma Runner - Fatal编程技术网

Angularjs 因果报应测试角度:如何设置范围

Angularjs 因果报应测试角度:如何设置范围,angularjs,angularjs-directive,karma-runner,Angularjs,Angularjs Directive,Karma Runner,我得到了一个相当复杂的角度指令,称为hy plugin window,我在ng repeat块()中使用它: 这意味着,在创建该指令时,列表中的每个指令都可以访问其唯一的内容(即对象pluginsDisplayed的单个成员)并执行以下操作: scope.statusMessage = 'Loading ' + scope.content.name + '...'; 一切都正常,除了我不知道如何用业力来检验它。通过这样一个相当常见的测试,我希望在指令中手动设置范围: 'use strict';

我得到了一个相当复杂的角度指令,称为
hy plugin window
,我在
ng repeat
块()中使用它:

这意味着,在创建该指令时,列表中的每个指令都可以访问其唯一的内容(即对象
pluginsDisplayed
的单个成员)并执行以下操作:

scope.statusMessage = 'Loading ' + scope.content.name + '...';
一切都正常,除了我不知道如何用业力来检验它。通过这样一个相当常见的测试,我希望在指令中手动设置范围:

'use strict';

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

    beforeEach(module('hyacinthHostApp'));

    var element, $compile, scope;

    beforeEach(inject(function(_$compile_, $rootScope) {
        $compile = _$compile_;
        scope = $rootScope.$new();
    }));


  it('should do something', inject(function () {

      scope.content = {
          name: "testElement",
          id: "testElement000",
          uiType: "canvas"
      };

      element = angular.element('<div hy-plugin-window></div>');
      element = $compile(element)(scope);

      //expect(...);
  }));
});
我的指令第一次尝试访问其
作用域.content.name


考虑到我是一个测试新手,我还缺少什么?

短篇故事:将编译后的元素更改为
,我认为它应该可以工作

该指令有一个隔离作用域,这意味着它不典型地从“常规”作用域继承

在测试中,您在常规作用域上定义
content
,但指令本身是封装的-它有独立的作用域,因此看不到在常规作用域上定义的
content
属性


您需要通过组件的显式接口(即
content
attribute)进行沟通。

Vojta Jina的回答!太棒了。
scope.statusMessage = 'Loading ' + scope.content.name + '...';
'use strict';

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

    beforeEach(module('hyacinthHostApp'));

    var element, $compile, scope;

    beforeEach(inject(function(_$compile_, $rootScope) {
        $compile = _$compile_;
        scope = $rootScope.$new();
    }));


  it('should do something', inject(function () {

      scope.content = {
          name: "testElement",
          id: "testElement000",
          uiType: "canvas"
      };

      element = angular.element('<div hy-plugin-window></div>');
      element = $compile(element)(scope);

      //expect(...);
  }));
});
TypeError: Cannot read property 'name' of undefined