Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix: resolve dynamic import warnings during jest tests

shamoon5e00c1c6767b
diff --git a/src-ui/setup-jest.ts b/src-ui/setup-jest.ts
index a688f4a6e..162884feb 100644
--- a/src-ui/setup-jest.ts
+++ b/src-ui/setup-jest.ts
@@ -120,3 +120,20 @@ Object.defineProperty(window, 'location', {
HTMLCanvasElement.prototype.getContext = <
typeof HTMLCanvasElement.prototype.getContext
>jest.fn()
+
+// pdfjs
+jest.mock('pdfjs-dist', () => ({
+ getDocument: jest.fn(() => ({
+ promise: Promise.resolve({ numPages: 3 }),
+ })),
+ GlobalWorkerOptions: { workerSrc: '' },
+ VerbosityLevel: { ERRORS: 0 },
+ globalThis: {
+ pdfjsLib: {
+ GlobalWorkerOptions: {
+ workerSrc: '',
+ },
+ },
+ },
+}))
+jest.mock('pdfjs-dist/web/pdf_viewer', () => ({}))