2

ブロックhy-plugin-window内で使用する、かなり複雑な Angular ディレクティブを取得しました(完全なディレクティブ コードはこちら)。ng-repeat

<div ng-repeat="pluginD in pluginsDisplayed">
    <div hy-plugin-window content="pluginD" remove="remove"></div>
</div>

contentディレクティブは、親のメンバーに双方向にリンクされている分離スコープを使用します。

return {
        restrict: 'A',
        replace: true,
        link: linker,
        scope: {
            content:'=',
        }
    };

これは、それが作成されると、リスト内のすべてのディレクティブがその一意のコンテンツ ( object の単一メンバーpluginsDisplayed) にアクセスして、次のようなことを実行できることを意味します。

scope.statusMessage = 'Loading ' + scope.content.name + '...';

Karma でテストする方法がわからないことを除いて、すべてが機能します。このようなかなり一般的なテストでは、ディレクティブ内でスコープを手動で設定したいと考えていました。

'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

私のディレクティブがそのscope.content.name.

私はテストの完全な初心者であることを考えると、何が欠けていますか?

4

1 に答える 1