|
| 1 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | +import { Component, DebugElement, input, TemplateRef, ViewContainerRef } from '@angular/core'; |
| 3 | +import { By } from '@angular/platform-browser'; |
1 | 4 | import { VisibleDirective } from './visible.directive';
|
2 |
| -import { TestBed } from '@angular/core/testing'; |
3 |
| -import { TemplateRef, ViewContainerRef } from '@angular/core'; |
| 5 | + |
| 6 | +@Component({ |
| 7 | + imports: [VisibleDirective], |
| 8 | + template: '<ng-template [cVisible]="visible()">Test Node</ng-template>' |
| 9 | +}) |
| 10 | +class TestComponent { |
| 11 | + readonly visible = input(true); |
| 12 | +} |
4 | 13 |
|
5 | 14 | describe('VisibleDirective', () => {
|
| 15 | + let component: TestComponent; |
| 16 | + let fixture: ComponentFixture<TestComponent>; |
| 17 | + let debugElement: DebugElement; |
| 18 | + |
6 | 19 | beforeEach(() => {
|
7 | 20 | TestBed.configureTestingModule({
|
| 21 | + imports: [TestComponent], |
8 | 22 | providers: [TemplateRef, ViewContainerRef]
|
9 |
| - }); |
| 23 | + }).compileComponents(); |
| 24 | + |
| 25 | + fixture = TestBed.createComponent(TestComponent); |
| 26 | + component = fixture.componentInstance; |
| 27 | + debugElement = fixture.debugElement.query(By.directive(VisibleDirective)); |
| 28 | + fixture.detectChanges(); |
10 | 29 | });
|
| 30 | + |
11 | 31 | it('should create an instance', () => {
|
12 | 32 | TestBed.runInInjectionContext(() => {
|
13 | 33 | const directive = new VisibleDirective();
|
|
0 commit comments