Skip to content

ReferenceError: WebGLRenderingContext is not defined in ngx-extended-pdf-viewer v. 23.0.0 #2866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
amazing4u opened this issue Apr 9, 2025 · 4 comments
Assignees
Labels
23 nuisance a bug that only shows in the logs; or: a bug with an obvious work-around every user finds quickly Solved

Comments

@amazing4u
Copy link

amazing4u commented Apr 9, 2025

When running jest tests after upgrading to ngx-extended-pdf-viewer v. 23.0.0 (in v. 22.0.0 everything works) i get:

ReferenceError: WebGLRenderingContext is not defined

> 1 | import { NgxExtendedPdfViewerModule, NgxExtendedPdfViewerService } from 'ngx-extended-pdf-viewer';
    | ^
  2 | import { PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
  3 |
  4 | import { provideHttpClient } from '@angular/common/http';

  at getSafeCanvasSize (node_modules/ngx-extended-pdf-viewer/fesm2022/ngx-extended-pdf-viewer.mjs:83:23)
  at Object.<anonymous> (node_modules/ngx-extended-pdf-viewer/fesm2022/ngx-extended-pdf-viewer.mjs:142:22)

The error is here:
Image

You added the code because of: #2568

The application works fine. The problem is only in tests. I searched in internet and what i found is that in tests many things are missing like window and there is no WebGLRenderingContext object. Maybe there is a way to mock this, but i could not find it.

Version info

  • Version of ngx-extended-pdf-viewer: 23.0.0
@stephanrauh
Copy link
Owner

I notice the same problem when trying to write a Jest test. However, your analysis allows me to solve it. Can you send me a simple smoke that that used to work in version 22, please? When trying to write a Jest test I had to mock so many things that I gave up after a while.

Thanks in advance,
Stephan

@stephanrauh stephanrauh self-assigned this Apr 11, 2025
@stephanrauh stephanrauh added nuisance a bug that only shows in the logs; or: a bug with an obvious work-around every user finds quickly Stephan wants to look at it! 23 labels Apr 11, 2025
stephanrauh added a commit that referenced this issue Apr 13, 2025
… to avoid having to mock a lot of browser objects
@stephanrauh
Copy link
Owner

I've added a test runner detection to the offending code. I hope it works with less mocking now.

I'd still appreciate it if you could send me a working Jest smoke test. When I tried to write a Jest test myself, I ended up with a lot of frustration...

Best regards,
Stephan

@amazing4u
Copy link
Author

Thank you. The fix worked! I will try to create a sample jest test in the coming days

@stephanrauh
Copy link
Owner

Perfect! A sample test would be (pun intented) amazing for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
23 nuisance a bug that only shows in the logs; or: a bug with an obvious work-around every user finds quickly Solved
Projects
None yet
Development

No branches or pull requests

2 participants