title: Need help to write jasmine unit test case for print functionality
body: <p>I have searched solution for this scenario. I found nothing. So, I am posting as a new question. I have a method in component which prints data in document like (control+P). </p>
  
  <pre><code>printContents;
    popupWin;
    print(): void { 
      this.printContents = document.getElementById('print-section2').innerHTML;
      this.popupWin = window.open('', '_blank', 'top=500,left=500,height=100%,width=auto');
      this.popupWin.document.open();
      this.popupWin.document.write(`
        &lt;html&gt;
          &lt;head&gt;
            &lt;title&gt;Zone 24x7 - Resource Allocation System
            &lt;/title&gt;
            &lt;/br&gt;
            &lt;/br&gt;
               &lt;style&gt;table,tr,td{
                                  border-collapse:collapse;  
                                  border:0.5px solid #000000;
                                      }&lt;/style&gt;
                                      &lt;style&gt;h3{justify-content:center}
                                      td{
                                        width: 40%
                                      }
                                      &lt;/style&gt;
  
          &lt;/head&gt;
      &lt;body onload="window.print();window.close()"&gt;${this.printContents}&lt;/body&gt;
        &lt;/html&gt;`
      );
      this.popupWin.print();
      this.popupWin.document.close();
    }
  </code></pre>
  
  <p>I have tried to write below testcase for that one.</p>
  
  <pre><code>it('Print method should called', () =&gt; {
      let viewEditResourceService = fixture.debugElement.injector.get(ViewEditResourceService);
      spyOn(viewEditResourceService, 'getResourcebyId').and.returnValue(Observable.of(allocationModalCompObj.resDetails.data));
      component.message = 298;
  
      spyOn(window, 'open');
      spyOn(document, 'open');
      spyOn(document, 'write');
      spyOn(window, 'print');
  
      component.ngOnInit();
      component.print();
      expect(window.open).toHaveBeenCalled();
      expect(window.print).toHaveBeenCalled();
  });
  </code></pre>
  
  <p>It is giving below error</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'document' of undefined
    TypeError: Cannot read property 'document' of undefined</p>
  </blockquote>
  
  <p>I understood that This error because of spying window object. Any help is highly appreciated. </p>