How can i test ng template ref from child component in angular 7

Viewed 127

show-data.component.html

<responsive [mobile]="mobile" [tablet]="tablet" [desktop]="desktop" ></responsive>
<ng-template #mobile>
<h1> hello from mobile </h1>
</ng-template>
<ng-template #tablet>
<h1> hello from tablet</h1>
</ng-template>
<ng-template #desktop>
<h1> hello from desktop</h1>
</ng-template>

show-data.component.ts

@Component({
  selector: 'app-show-data',
  templateUrl: './show-data.component.html',
  styleUrls: ['./show-data.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class ShowData implements OnInit {

 @ViewChild(ResponsiveComponent) resp: any;

}

my ng-template is not getting loaded when i try to create karma testcase like this

show-data.component.spec.ts

describe('ShowData', () => {
  let component: ShowData;
  let fixture: ComponentFixture<ShowData>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ ShowData ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ShowData);
    component = fixture.componentInstance;
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

i'm not understanding how to write karma testcase for this component. I need the test cases for the elements inside the templateRefs like mobile, tablet,desktop Except for the code, a reference in Angular 7 testing for beginners would be appreciated.

0 Answers
Related