Currently, I am working on writing a Jasmine test for the print function shown below:
printContent( contentName: string ) {
this._console.Information( `${this.codeName}.printContent: ${contentName}`)
let printContents = document.getElementById( contentName ).innerHTML;
const windowPrint = window.open('', '', 'left=0,top=0,width=925,height=1400,toolbar=0,scrollbars=0,status=0');
windowPrint.document.write(printContents);
windowPrint.document.close();
windowPrint.focus();
windowPrint.print();
windowPrint.close();
}
I am open to modifying the function to make it more easily testable. This is the current test I have written:
it( 'printContent should open a window ...', fakeAsync( () => {
spyOn( window, 'open' );
sut.printContent( 'printContent' );
expect( window.open ).toHaveBeenCalled();
}) );
Improving code coverage is my main goal at the moment.