Reputation: 547
While writing test cases for angular 4 app we are facing some issues.
1)Unable to create fixture Textbed object of service/component when they have methods which deal with HTML tags.
(e.g.
overlayOn() { document.getElementById("overlay").style.display = "block"; } overlayOff() {document.getElementById("overlay").style.display = "none"; }
)
Error :unable to set style of undefined.
2)Issue in mocking ViewChild() , EventEmitter(),@Output() and @Input() elements.
Error :unable to set property of undefined.
Basically whenever we are dealing with html Tags in type script code, then we are getting errors in writing test cases.
Please help if there is any way to mock or set these tags in test cases.
Upvotes: 0
Views: 628
Reputation: 17494
Try
For HTML:
<div id="overlay" style="display: none"></div>
the js file:
it('should not display id "overlay"', () => {
let containerElement = fixture.debugElement.query(By.css('#overlay')).nativeElement.style.display;
expect(containerElement).toBe('none');
})
Upvotes: 1