From d9ec23e46bb129116c761ec79a7ddaa28a4ab68b Mon Sep 17 00:00:00 2001 From: Matthieu Riegler Date: Tue, 10 Feb 2026 01:25:25 +0100 Subject: [PATCH] test: add test about mapped attributes to input The dynamic component has `[value]` in its selector and this has always been reflected as a DOM attribute on the dynamically created host element, which is now also synced into the component instance. fixes #60157 (cherry picked from commit e229328b394b89f2f55b990ae9c3a4176b1e2585) --- .../core/test/acceptance/directive_spec.ts | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/packages/core/test/acceptance/directive_spec.ts b/packages/core/test/acceptance/directive_spec.ts index d75115f8629..a1d95d43fac 100644 --- a/packages/core/test/acceptance/directive_spec.ts +++ b/packages/core/test/acceptance/directive_spec.ts @@ -7,6 +7,7 @@ */ import {CommonModule} from '@angular/common'; +import {By} from '@angular/platform-browser'; import { Component, Directive, @@ -24,7 +25,6 @@ import { ViewContainerRef, } from '../../src/core'; import {TestBed} from '../../testing'; -import {By} from '@angular/platform-browser'; describe('directives', () => { beforeEach(() => { @@ -1007,6 +1007,60 @@ describe('directives', () => { ref.setInput('value', 'hello'); expect(ref.instance.value).toBe(1); }); + + it('should map attribute to input when specific in the selecotr', () => { + @Component({ + selector: 'app-test[value]', + template: ``, + }) + class TestComponent { + @Input() value = 'unset'; + } + + @Component({ + selector: 'app-root', + template: ``, + }) + class App { + constructor(vcr: ViewContainerRef) { + vcr.createComponent(TestComponent); + } + } + + const fixture = TestBed.createComponent(App); + const testComponent = fixture.debugElement.query( + By.directive(TestComponent), + ).componentInstance; + fixture.detectChanges(); + + expect(testComponent.value).toBe(''); + }); + + it('should not map attribute to input when not specified in the selector', () => { + @Component({ + selector: 'app-test', + template: ``, + }) + class TestComponent { + @Input() value = 'unset'; + } + + @Component({ + selector: 'app-root', + template: ``, + }) + class App { + constructor(vcr: ViewContainerRef) { + vcr.createComponent(TestComponent); + } + } + + const fixture = TestBed.createComponent(App); + const testComponent = fixture.debugElement.query( + By.directive(TestComponent), + ).componentInstance; + expect(testComponent.value).toBe('unset'); + }); }); describe('outputs', () => {