expect(() => {
   createDirectiveVariableBindings(new RenderElementBinder({variableBindings: new Map()}), [
     directiveBinding({metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})}),
     directiveBinding(
         {metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})})
   ]);
 }).not.toThrow();
 expect(() => {
   createDirectiveVariableBindings(
       new RenderElementBinder({
         variableBindings:
             MapWrapper.createFromStringMap<string>({"exportName": "templateName"})
       }),
       [
         directiveBinding(
             {metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})}),
         directiveBinding(
             {metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})})
       ]);
 }).toThrowError(new RegExp("More than one directive have exportAs = 'exportName'"));
      it("should calculate directive variable bindings", () => {
        var dvbs = createDirectiveVariableBindings(
            new RenderElementBinder({
              variableBindings:
                  MapWrapper.createFromStringMap<string>({"exportName": "templateName"})
            }),
            [
              directiveBinding(
                  {metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})}),
              directiveBinding(
                  {metadata: RenderDirectiveMetadata.create({exportAs: 'otherName'})})
            ]);

        expect(dvbs).toEqual(MapWrapper.createFromStringMap<number>({"templateName": 0}));
      });
 expect(() => {
   createDirectiveVariableBindings(
       new RenderElementBinder({
         variableBindings:
             MapWrapper.createFromStringMap<string>({"someInvalidName": "templateName"})
       }),
       [
         directiveBinding(
             {metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})})
       ]);
 }).toThrowError(new RegExp("Cannot find directive with exportAs = 'someInvalidName'"));
      it("should set exportAs to $implicit for component with exportAs = null", () => {
        var dvbs = createDirectiveVariableBindings(
            new RenderElementBinder({
              variableBindings:
                  MapWrapper.createFromStringMap<string>({"$implicit": "templateName"})
            }),
            [
              directiveBinding({
                metadata: RenderDirectiveMetadata.create(
                    {exportAs: null, type: RenderDirectiveMetadata.COMPONENT_TYPE})
              })
            ]);

        expect(dvbs).toEqual(MapWrapper.createFromStringMap<number>({"templateName": 0}));
      });
Beispiel #6
0
      it('should parse host configuration', () => {
        var md = RenderDirectiveMetadata.create({
          host: MapWrapper.createFromPairs([
            ['(event)', 'eventVal'],
            ['[prop]', 'propVal'],
            ['@action', 'actionVal'],
            ['attr', 'attrVal']
          ])
        });

        expect(md.hostListeners).toEqual(MapWrapper.createFromPairs([['event', 'eventVal']]));
        expect(md.hostProperties).toEqual(MapWrapper.createFromPairs([['prop', 'propVal']]));
        expect(md.hostActions).toEqual(MapWrapper.createFromPairs([['action', 'actionVal']]));
        expect(md.hostAttributes).toEqual(MapWrapper.createFromPairs([['attr', 'attrVal']]));
      });
        it('should return host event records', () => {
          var rec = creator.getEventBindingRecords(
              [
                new RenderElementBinder({
                  eventBindings: [],
                  directives: [
                    new DirectiveBinder(
                        {directiveIndex: 0, eventBindings: [new EventBinding("a", null)]})
                  ]
                })
              ],
              [RenderDirectiveMetadata.create({id: 'some-id'})]);

          expect(rec.length).toEqual(1);
          expect(rec[0].eventName).toEqual("a");
          expect(rec[0].implicitReceiver).toBeAnInstanceOf(DirectiveIndex);
        });
          process(el('<some-comp></some-comp>'), null, [someComponent, someComponentDup]);
        }).toThrowError(new RegExp('Only one component directive is allowed per element'));
      });

      it('should sort the directives and store the component as the first directive', () => {
        var results = process(el('<some-comp some-decor></some-comp>'));
        expect(annotatedDirectives[results[0].directives[0].directiveIndex].id)
            .toEqual('someComponent');
        expect(annotatedDirectives[results[0].directives[1].directiveIndex].id)
            .toEqual('someDirective');
      });
    });
  });
}

var someComponent = RenderDirectiveMetadata.create(
    {selector: 'some-comp', id: 'someComponent', type: RenderDirectiveMetadata.COMPONENT_TYPE});

var someComponentDup = RenderDirectiveMetadata.create(
    {selector: 'some-comp', id: 'someComponentDup', type: RenderDirectiveMetadata.COMPONENT_TYPE});

var someComponent2 = RenderDirectiveMetadata.create(
    {selector: 'some-comp2', id: 'someComponent2', type: RenderDirectiveMetadata.COMPONENT_TYPE});

var someDirective = RenderDirectiveMetadata.create(
    {selector: '[some-decor]', id: 'someDirective', type: RenderDirectiveMetadata.DIRECTIVE_TYPE});

var someDirectiveIgnoringChildren = RenderDirectiveMetadata.create({
  selector: '[some-decor-ignoring-children]',
  compileChildren: false,
  type: RenderDirectiveMetadata.DIRECTIVE_TYPE