From 7cda85d385b140248d44adb25ae95b1914ca1c5f Mon Sep 17 00:00:00 2001 From: MG Date: Sat, 5 Sep 2020 15:22:38 +0200 Subject: [PATCH] fix: cannot combine @Input decorators with query decorators closes #181 Signed-off-by: MG --- lib/common/decorate.ts | 5 ++- lib/mock-component/mock-component.ts | 2 +- lib/mock-directive/mock-directive.ts | 2 +- tests/issue-181/test.spec.ts | 63 ++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/issue-181/test.spec.ts diff --git a/lib/common/decorate.ts b/lib/common/decorate.ts index b5baa205cd..fcea74f5d0 100644 --- a/lib/common/decorate.ts +++ b/lib/common/decorate.ts @@ -13,10 +13,13 @@ import { Type } from './lib'; * * @internal */ -export function decorateInputs(cls: Type, inputs?: string[]) { +export function decorateInputs(cls: Type, inputs?: string[], exclude?: string[]) { if (inputs) { for (const input of inputs) { const [key, alias] = input.split(': '); + if (exclude && exclude.indexOf(key) !== -1) { + continue; + } Input(alias)(cls.prototype, key); } } diff --git a/lib/mock-component/mock-component.ts b/lib/mock-component/mock-component.ts index cf57aa6dc5..2534ec620c 100644 --- a/lib/mock-component/mock-component.ts +++ b/lib/mock-component/mock-component.ts @@ -201,7 +201,7 @@ export function MockComponent( } } - decorateInputs(ComponentMock, inputs); + decorateInputs(ComponentMock, inputs, queries ? Object.keys(queries) : undefined); decorateOutputs(ComponentMock, outputs); decorateQueries(ComponentMock, queries); diff --git a/lib/mock-directive/mock-directive.ts b/lib/mock-directive/mock-directive.ts index bb5bd29904..26134ea38a 100644 --- a/lib/mock-directive/mock-directive.ts +++ b/lib/mock-directive/mock-directive.ts @@ -156,7 +156,7 @@ export function MockDirective(directive: Type): Type { + beforeEach(() => MockBuilder().keep(TargetModule)); + + it('should create the component', () => { + const fixture = MockRender(` + + + header + + + `); + expect(ngMocks.findInstance(fixture.debugElement, TargetComponent).header).toBeTruthy(); + expect(ngMocks.findInstance(fixture.debugElement, TargetDirective).header).toBeTruthy(); + }); +}); + +describe('issue-181:mock', () => { + beforeEach(() => MockBuilder().mock(TargetModule)); + + // it fails in e2e with enabled ivy only. + it('should create the component', () => { + const fixture = MockRender(` + + + header + + + `); + expect(ngMocks.findInstance(fixture.debugElement, TargetComponent).header).toBeTruthy(); + expect(ngMocks.findInstance(fixture.debugElement, TargetDirective).header).toBeTruthy(); + }); +});