【发布时间】:2020-11-28 18:29:47
【问题描述】:
我正在尝试为以下打印功能编写 Jasmine 测试:
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();
}
我非常愿意将函数更改为更具可测试性。这是我目前的测试:
it( 'printContent should open a window ...', fakeAsync( () => {
spyOn( window, 'open' );
sut.printContent( 'printContent' );
expect( window.open ).toHaveBeenCalled();
}) );
我正在努力获得更好的代码覆盖率。
【问题讨论】:
-
您当前的测试有什么问题?
标签: javascript angular typescript jasmine