I am trying to test @Input in angular 2 .@Input hide or show my p tag .I want to test this functionality using jasmine.
here is my component
import { Component,Input } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular 4';
@Input() enable:boolean
constructor() { }
}
testing code.
describe('@Input property ', () => {
it('will not show p tag', () => {
component.enable = false;
fixture.detectChanges();
PEl = fixture.debugElement.query(By.css('p'));
console.log(PEl.nativeElement);
expect(PEl.nativeElement.length).toEqual(0);
})
})
https://stackblitz.com/edit/angular-testing-wzxrin?file=app%2Fapp.component.spec.ts
*ngIfand it's false then the element will not be rendered to the dom tree. So yourPEl = fixture.debugElement.query(By.css('p'));returns nothing... that is what you would have to check in your test.0but it not works for me