mockContentWindow.onafterprint(new Event('afterprint'))
}
+ tick(500)
+
expect(removeChildSpy).toHaveBeenCalledWith(mockIframe)
expect(revokeObjectURLSpy).toHaveBeenCalledWith('blob:mock-url')
mockIframe.onload(new Event('load'))
}
+ tick(500)
+
expect(toastSpy).toHaveBeenCalled()
expect(removeChildSpy).toHaveBeenCalledWith(mockIframe)
expect(revokeObjectURLSpy).toHaveBeenCalledWith('blob:mock-url')
import { PDFDocumentProxy, PdfViewerModule } from 'ng2-pdf-viewer'
import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons'
import { DeviceDetectorService } from 'ngx-device-detector'
-import { BehaviorSubject, Observable, of, Subject } from 'rxjs'
+import { BehaviorSubject, Observable, of, Subject, timer } from 'rxjs'
import {
catchError,
debounceTime,
iframe.contentWindow.focus()
iframe.contentWindow.print()
iframe.contentWindow.onafterprint = () => {
- document.body.removeChild(iframe)
- URL.revokeObjectURL(blobUrl)
+ timer(500).subscribe(() => {
+ // delay to avoid print failure
+ document.body.removeChild(iframe)
+ URL.revokeObjectURL(blobUrl)
+ })
}
} catch (err) {
this.toastService.showError($localize`Print failed.`, err)
- document.body.removeChild(iframe)
- URL.revokeObjectURL(blobUrl)
+ timer(500).subscribe(() => {
+ // delay to avoid print failure
+ document.body.removeChild(iframe)
+ URL.revokeObjectURL(blobUrl)
+ })
}
}
},