From 13874b9955d7182bc45f7eabfb19253fd6e12d9c Mon Sep 17 00:00:00 2001 From: Isaac Datlof Date: Sat, 24 Mar 2018 20:49:37 -0400 Subject: [PATCH] fix: multiple decorators on an input --- lib/common/reflect.ts | 8 ++++---- lib/mock-component/mock-component.spec.ts | 8 ++++++++ .../test-components/simple-component.component.ts | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/common/reflect.ts b/lib/common/reflect.ts index f964b8bae3..87adfd815f 100644 --- a/lib/common/reflect.ts +++ b/lib/common/reflect.ts @@ -10,8 +10,8 @@ export function getInputsOutputs(directive: Type, type: ' return []; } const propertyMetadata = (directive as any).__prop__metadata__ || {}; - const outputs = Object.keys(propertyMetadata) - .filter((meta) => propertyMetadata[meta][0].ngMetadataName === type) - .reduce(metaReducer(propertyMetadata), []); - return outputs.concat(getInputsOutputs((directive as any).__proto__, type)); + return Object.keys(propertyMetadata) + .filter((meta) => propertyMetadata[meta].find((m: any) => m.ngMetadataName === type)) + .reduce(metaReducer(propertyMetadata), []) + .concat(getInputsOutputs((directive as any).__proto__, type)); } diff --git a/lib/mock-component/mock-component.spec.ts b/lib/mock-component/mock-component.spec.ts index 0aa7055af8..167cdd4324 100644 --- a/lib/mock-component/mock-component.spec.ts +++ b/lib/mock-component/mock-component.spec.ts @@ -11,6 +11,7 @@ import { SimpleComponent } from './test-components/simple-component.component'; template: ` @@ -61,6 +62,13 @@ describe('MockComponent', () => { expect(mockedComponent.someInput2).toEqual('bye'); }); + it('has no issues with multiple decorators on an input', () => { + fixture.detectChanges(); + const mockedComponent = fixture.debugElement + .query(By.directive(MockComponent(SimpleComponent))); + expect(mockedComponent.componentInstance.someInput3).toEqual(true); + }); + it('should trigger output bound behavior', () => { fixture.detectChanges(); const mockedComponent = fixture.debugElement diff --git a/lib/mock-component/test-components/simple-component.component.ts b/lib/mock-component/test-components/simple-component.component.ts index f0bb0cd2a5..64a31ff02d 100644 --- a/lib/mock-component/test-components/simple-component.component.ts +++ b/lib/mock-component/test-components/simple-component.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { Component, EventEmitter, HostBinding, Input, Output } from '@angular/core'; @Component({ selector: 'base-simple-component', @@ -17,6 +17,7 @@ export class BaseSimpleComponent { export class SimpleComponent extends BaseSimpleComponent { @Input() someInput: string; @Input('someOtherInput') someInput2: string; + @HostBinding('class.someClass') @Input() someInput3: boolean; @Output() someOutput1: EventEmitter; } /* tslint:enable:max-classes-per-file */