diff --git a/src/Document.spec.jsx b/src/Document.spec.jsx index b9d3c71f8..7efb5fa16 100644 --- a/src/Document.spec.jsx +++ b/src/Document.spec.jsx @@ -61,6 +61,7 @@ describe('Document', () => { ); expect.assertions(2); + await expect(onSourceSuccessPromise).resolves.toBe(OK); await expect(onLoadSuccessPromise).resolves.toMatchObject(desiredLoadedPdf); }); @@ -78,6 +79,7 @@ describe('Document', () => { ); expect.assertions(2); + await expect(onSourceSuccessPromise).resolves.toBe(OK); await expect(onLoadSuccessPromise).resolves.toMatchObject(desiredLoadedPdf); }); @@ -96,6 +98,7 @@ describe('Document', () => { ); expect.assertions(2); + await expect(onSourceSuccessPromise).resolves.toBe(OK); await expect(onLoadSuccessPromise).resolves.toMatchObject(desiredLoadedPdf); }); @@ -113,6 +116,7 @@ describe('Document', () => { ); expect.assertions(2); + await expect(onSourceSuccessPromise).resolves.toBe(OK); await expect(onLoadSuccessPromise).resolves.toMatchObject(desiredLoadedPdf); }); @@ -130,6 +134,7 @@ describe('Document', () => { ); expect.assertions(2); + await expect(onSourceSuccessPromise).resolves.toBe(OK); await expect(onLoadSuccessPromise).resolves.toMatchObject(desiredLoadedPdf); }); @@ -350,6 +355,7 @@ describe('Document', () => { await onLoadSuccessPromise; const child = getByTestId(container, 'child'); + expect(child.dataset.rendermode).toBe('svg'); }); @@ -367,6 +373,7 @@ describe('Document', () => { await onLoadSuccessPromise; const child = getByTestId(container, 'child'); + expect(child.dataset.rotate).toBe('90'); }); @@ -389,6 +396,7 @@ describe('Document', () => { await onLoadSuccessPromise; const child = getByTestId(container, 'child'); + expect(child.dataset.rendermode).toBe('canvas'); }); @@ -406,6 +414,7 @@ describe('Document', () => { await onLoadSuccessPromise; const child = getByTestId(container, 'child'); + expect(child.dataset.rotate).toBe('180'); }); }); diff --git a/src/Outline.spec.jsx b/src/Outline.spec.jsx index 491f0b8bb..7bda64462 100644 --- a/src/Outline.spec.jsx +++ b/src/Outline.spec.jsx @@ -36,6 +36,7 @@ describe('Outline', () => { render(); expect.assertions(1); + await expect(onLoadSuccessPromise).resolves.toMatchObject(desiredLoadedOutline); }); @@ -47,6 +48,7 @@ describe('Outline', () => { render(); expect.assertions(1); + await expect(onLoadErrorPromise).resolves.toBeInstanceOf(Error); restoreConsole(); @@ -58,6 +60,7 @@ describe('Outline', () => { const { rerender } = render(); expect.assertions(2); + await expect(onLoadSuccessPromise).resolves.toMatchObject(desiredLoadedOutline); const { func: onLoadSuccess2, promise: onLoadSuccessPromise2 } = makeAsyncCallback(); @@ -88,6 +91,7 @@ describe('Outline', () => { ); expect.assertions(1); + await onLoadSuccessPromise; const wrapper = container.querySelector('.react-pdf__Outline'); @@ -103,6 +107,7 @@ describe('Outline', () => { render(); expect.assertions(2); + await onLoadSuccessPromise; expect(inputRef).toHaveBeenCalled(); @@ -115,6 +120,7 @@ describe('Outline', () => { render(); expect.assertions(1); + await onLoadSuccessPromise; const items = screen.getAllByRole('listitem'); diff --git a/src/Page.spec.jsx b/src/Page.spec.jsx index 3ebaee3d7..5dedb8dad 100644 --- a/src/Page.spec.jsx +++ b/src/Page.spec.jsx @@ -61,6 +61,7 @@ describe('Page', () => { render(); expect.assertions(1); + await expect(onLoadSuccessPromise).resolves.toMatchObject(desiredLoadedPage); }); @@ -89,6 +90,7 @@ describe('Page', () => { render(); expect.assertions(1); + await expect(onLoadErrorPromise).resolves.toBeInstanceOf(Error); restoreConsole(); @@ -124,6 +126,7 @@ describe('Page', () => { render(); expect.assertions(1); + await expect(registerPagePromise).resolves.toMatchObject(registerPageArguments); }); @@ -135,6 +138,7 @@ describe('Page', () => { unmount(); expect.assertions(1); + await expect(nuregisterPagePromise).resolves.toBe(unregisterPageArguments); }); @@ -144,6 +148,7 @@ describe('Page', () => { const { rerender } = render(); expect.assertions(2); + await expect(onLoadSuccessPromise).resolves.toMatchObject(desiredLoadedPage); const { func: onLoadSuccess2, promise: onLoadSuccessPromise2 } = makeAsyncCallback(); @@ -159,6 +164,7 @@ describe('Page', () => { const { rerender } = render(); expect.assertions(2); + await expect(onLoadSuccessPromise).resolves.toMatchObject(desiredLoadedPage); const { func: onLoadSuccess2, promise: onLoadSuccessPromise2 } = makeAsyncCallback(); diff --git a/src/Page/AnnotationLayer.spec.jsx b/src/Page/AnnotationLayer.spec.jsx index 9cdafd289..ded157b76 100644 --- a/src/Page/AnnotationLayer.spec.jsx +++ b/src/Page/AnnotationLayer.spec.jsx @@ -49,6 +49,7 @@ describe('AnnotationLayer', () => { ); expect.assertions(1); + await expect(onGetAnnotationsSuccessPromise).resolves.toMatchObject(desiredAnnotations); }); @@ -67,6 +68,7 @@ describe('AnnotationLayer', () => { ); expect.assertions(1); + await expect(onGetAnnotationsErrorPromise).resolves.toBeInstanceOf(Error); restoreConsole(); @@ -85,6 +87,7 @@ describe('AnnotationLayer', () => { ); expect.assertions(2); + await expect(onGetAnnotationsSuccessPromise).resolves.toMatchObject(desiredAnnotations); const { func: onGetAnnotationsSuccess2, promise: onGetAnnotationsSuccessPromise2 } = @@ -130,6 +133,7 @@ describe('AnnotationLayer', () => { await onRenderAnnotationLayerSuccessPromise; const annotationItems = [...container.firstElementChild.children]; + expect(annotationItems).toHaveLength(desiredAnnotations.length); }); @@ -232,8 +236,9 @@ describe('AnnotationLayer', () => { const annotationLayer = container.firstElementChild; - // Expect the annotation layer to be rotated const viewport = page.getViewport({ scale: 1 }); + + // Expect the annotation layer to be rotated expect(parseInt(annotationLayer.style.width, 10)).toBe(Math.floor(viewport.width)); expect(parseInt(annotationLayer.style.height, 10)).toBe(Math.floor(viewport.height)); }); @@ -260,8 +265,9 @@ describe('AnnotationLayer', () => { const annotationLayer = container.firstElementChild; - // Expect the annotation layer to be scaled const viewport = page.getViewport({ scale }); + + // Expect the annotation layer to be scaled expect(parseInt(annotationLayer.style.width, 10)).toBe(Math.floor(viewport.width)); expect(parseInt(annotationLayer.style.height, 10)).toBe(Math.floor(viewport.height)); }); @@ -292,6 +298,7 @@ describe('AnnotationLayer', () => { await onRenderAnnotationLayerSuccessPromise; const stringifiedAnnotationLayerNode = container.outerHTML; + expect(stringifiedAnnotationLayerNode).toMatch(desiredImageTagRegExp); }); @@ -322,6 +329,7 @@ describe('AnnotationLayer', () => { await onRenderAnnotationLayerSuccessPromise; const stringifiedAnnotationLayerNode = container.outerHTML; + expect(stringifiedAnnotationLayerNode).toMatch(desiredImageTagRegExp); }); }); diff --git a/src/Page/TextLayer.spec.jsx b/src/Page/TextLayer.spec.jsx index 7ee1b9fe5..acc797868 100644 --- a/src/Page/TextLayer.spec.jsx +++ b/src/Page/TextLayer.spec.jsx @@ -40,6 +40,7 @@ describe('TextLayer', () => { render(); expect.assertions(1); + await expect(onGetTextSuccessPromise).resolves.toMatchObject({ items: desiredTextItems }); }); @@ -51,6 +52,7 @@ describe('TextLayer', () => { render(); expect.assertions(1); + await expect(onGetTextErrorPromise).resolves.toBeInstanceOf(Error); restoreConsole(); @@ -62,6 +64,7 @@ describe('TextLayer', () => { const { rerender } = render(); expect.assertions(2); + await expect(onGetTextSuccessPromise).resolves.toMatchObject({ items: desiredTextItems, }); @@ -98,6 +101,7 @@ describe('TextLayer', () => { await onRenderTextLayerSuccessPromise; const textItems = [...container.firstElementChild.children]; + expect(textItems).toHaveLength(desiredTextItems.length + 1); }); @@ -120,6 +124,7 @@ describe('TextLayer', () => { await onRenderTextLayerSuccessPromise; const textItems = [...container.firstElementChild.children]; + expect(textItems).toHaveLength(desiredTextItems.length + 1); }); @@ -176,6 +181,7 @@ describe('TextLayer', () => { await onRenderTextLayerSuccessPromise; const textItems = [...container.firstElementChild.children]; + expect(textItems).toHaveLength(desiredTextItems.length + 1); expect(customTextRenderer).toHaveBeenCalledTimes(desiredTextItems.length);