@@ -15,7 +15,6 @@ import DocumentContext from './DocumentContext.js';
1515
1616import type { PDFDocumentProxy , PDFPageProxy } from 'pdfjs-dist' ;
1717import type { DocumentContextType , PageCallback } from './shared/types.js' ;
18- import type { OptionalContentConfig } from 'pdfjs-dist/types/src/display/optional_content_config.js' ;
1918
2019const pdfFile = await loadPDF ( '../../__mocks__/_pdf.pdf' ) ;
2120const pdfFile2 = await loadPDF ( '../../__mocks__/_pdf2.pdf' ) ;
@@ -739,7 +738,7 @@ describe('Page', () => {
739738 expect ( annotationLayer ) . not . toBeInTheDocument ( ) ;
740739 } ) ;
741740
742- it ( 'requests page to be rendered with default visibility for optionalContentConfig' , async ( ) => {
741+ it ( 'requests page to be rendered with default visibility given no optionalContentConfig' , async ( ) => {
743742 const { func : onRenderSuccess , promise : onRenderSuccessPromise } =
744743 makeAsyncCallback < [ PageCallback ] > ( ) ;
745744
@@ -754,36 +753,46 @@ describe('Page', () => {
754753 await onRenderSuccessPromise ;
755754
756755 const pageCanvas = container . querySelector ( '.react-pdf__Page__canvas' ) as HTMLCanvasElement ;
757- const context : CanvasRenderingContext2D = pageCanvas . getContext ( '2d' ) ! ;
758- const imageData : ImageData = context . getImageData ( 100 , 100 , 1 , 1 ) ;
756+ const context = pageCanvas . getContext ( '2d' ) ;
759757
760- // should render green pixel because the layer is visible
758+ if ( ! context ) {
759+ throw new Error ( 'CanvasRenderingContext2D is not available' ) ;
760+ }
761+
762+ const imageData = context . getImageData ( 100 , 100 , 1 , 1 ) ;
763+
764+ // Should render green pixel because the layer is visible
761765 expect ( imageData . data ) . toStrictEqual ( new Uint8ClampedArray ( [ 191 , 255 , 191 , 255 ] ) ) ;
762766 } ) ;
763767
764768 it ( 'requests page to be rendered with given optionalContentConfig' , async ( ) => {
765769 const { func : onRenderSuccess , promise : onRenderSuccessPromise } =
766770 makeAsyncCallback < [ PageCallback ] > ( ) ;
767- const optionalContentConfig : OptionalContentConfig = await pdf5 . getOptionalContentConfig ( ) ;
768771
772+ const optionalContentConfig = await pdf5 . getOptionalContentConfig ( ) ;
769773 optionalContentConfig . setVisibility ( '1R' , false ) ;
770774
771775 const { container } = renderWithContext (
772776 < Page onRenderSuccess = { onRenderSuccess } pageIndex = { 0 } /> ,
773777 {
774- optionalContentConfig,
775778 linkService,
779+ optionalContentConfig,
776780 pdf : pdf5 ,
777781 } ,
778782 ) ;
779783
780784 await onRenderSuccessPromise ;
781785
782786 const pageCanvas = container . querySelector ( '.react-pdf__Page__canvas' ) as HTMLCanvasElement ;
783- const context : CanvasRenderingContext2D = pageCanvas . getContext ( '2d' ) ! ;
784- const imageData : ImageData = context . getImageData ( 100 , 100 , 1 , 1 ) ;
787+ const context = pageCanvas . getContext ( '2d' ) ;
788+
789+ if ( ! context ) {
790+ throw new Error ( 'CanvasRenderingContext2D is not available' ) ;
791+ }
792+
793+ const imageData = context . getImageData ( 100 , 100 , 1 , 1 ) ;
785794
786- // should render white pixel because the layer is hidden
795+ // Should render white pixel because the layer is hidden
787796 expect ( imageData . data ) . toStrictEqual ( new Uint8ClampedArray ( [ 255 , 255 , 255 , 255 ] ) ) ;
788797 } ) ;
789798 } ) ;
0 commit comments