|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {DOCUMENT} from '@angular/common'; |
10 | | -import {ApplicationRef, Component, ComponentRef, createComponent, createEnvironmentInjector, Directive, ElementRef, EmbeddedViewRef, EnvironmentInjector, inject, Injectable, InjectionToken, Injector, Input, NgModule, OnDestroy, reflectComponentType, Renderer2, Type, ViewChild, ViewContainerRef, ViewEncapsulation, ɵsetDocument} from '@angular/core'; |
| 9 | +import {DOCUMENT, NgIf} from '@angular/common'; |
| 10 | +import {ApplicationRef, Component, ComponentRef, createComponent, createEnvironmentInjector, Directive, ElementRef, EmbeddedViewRef, EnvironmentInjector, forwardRef, inject, Injectable, InjectionToken, Injector, Input, NgModule, OnDestroy, reflectComponentType, Renderer2, Type, ViewChild, ViewContainerRef, ViewEncapsulation, ɵsetDocument} from '@angular/core'; |
11 | 11 | import {stringifyForError} from '@angular/core/src/render3/util/stringify_utils'; |
12 | 12 | import {TestBed} from '@angular/core/testing'; |
13 | 13 | import {expect} from '@angular/platform-browser/testing/src/matchers'; |
@@ -400,6 +400,68 @@ describe('component', () => { |
400 | 400 | .toThrowError( |
401 | 401 | /NG0300: Multiple components match node with tagname comp: CompA and CompB/); |
402 | 402 | }); |
| 403 | + |
| 404 | + it('should not throw if a standalone component imports itself', () => { |
| 405 | + @Component({ |
| 406 | + selector: 'comp', |
| 407 | + template: '<comp *ngIf="recurse"/>hello', |
| 408 | + standalone: true, |
| 409 | + imports: [Comp, NgIf] |
| 410 | + }) |
| 411 | + class Comp { |
| 412 | + @Input() recurse = false; |
| 413 | + } |
| 414 | + |
| 415 | + @Component({ |
| 416 | + template: '<comp [recurse]="true"/>', |
| 417 | + standalone: true, |
| 418 | + imports: [Comp], |
| 419 | + }) |
| 420 | + class App { |
| 421 | + } |
| 422 | + |
| 423 | + let textContent = ''; |
| 424 | + |
| 425 | + expect(() => { |
| 426 | + const fixture = TestBed.createComponent(App); |
| 427 | + fixture.detectChanges(); |
| 428 | + textContent = fixture.nativeElement.textContent.trim(); |
| 429 | + }).not.toThrow(); |
| 430 | + |
| 431 | + // Ensure that the component actually rendered. |
| 432 | + expect(textContent).toBe('hellohello'); |
| 433 | + }); |
| 434 | + |
| 435 | + it('should not throw if a standalone component imports itself using a forwardRef', () => { |
| 436 | + @Component({ |
| 437 | + selector: 'comp', |
| 438 | + template: '<comp *ngIf="recurse"/>hello', |
| 439 | + standalone: true, |
| 440 | + imports: [forwardRef(() => Comp), NgIf] |
| 441 | + }) |
| 442 | + class Comp { |
| 443 | + @Input() recurse = false; |
| 444 | + } |
| 445 | + |
| 446 | + @Component({ |
| 447 | + template: '<comp [recurse]="true"/>', |
| 448 | + standalone: true, |
| 449 | + imports: [Comp], |
| 450 | + }) |
| 451 | + class App { |
| 452 | + } |
| 453 | + |
| 454 | + let textContent = ''; |
| 455 | + |
| 456 | + expect(() => { |
| 457 | + const fixture = TestBed.createComponent(App); |
| 458 | + fixture.detectChanges(); |
| 459 | + textContent = fixture.nativeElement.textContent.trim(); |
| 460 | + }).not.toThrow(); |
| 461 | + |
| 462 | + // Ensure that the component actually rendered. |
| 463 | + expect(textContent).toBe('hellohello'); |
| 464 | + }); |
403 | 465 | }); |
404 | 466 |
|
405 | 467 | it('should use a new ngcontent attribute for child elements created w/ Renderer2', () => { |
|
0 commit comments