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 e229328b39)
This commit is contained in:
Matthieu Riegler
2026-02-10 01:25:25 +01:00
committed by Andrew Kushnir
parent a5bd444880
commit d9ec23e46b
@@ -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', () => {