# react-pdf-testing-library

> Tools for react-pdf visual testing

Latest version **0.0.1** (published 2021-05-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-pdf-testing-library
pnpm add react-pdf-testing-library
yarn add react-pdf-testing-library
bun add react-pdf-testing-library
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2021-05-13 |
| First published | 2021-05-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 34.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Dmitry Ivakhnenko |
| Maintainers | jeetiss |

## Links

- npm: https://www.npmjs.com/package/react-pdf-testing-library
- Repository: https://github.com/jeetiss/react-pdf-testing-library
- Homepage: https://github.com/jeetiss/react-pdf-testing-library#readme
- Issues: https://github.com/jeetiss/react-pdf-testing-library/issues
- npm.io page: https://npm.io/package/react-pdf-testing-library

## Dependencies (3)

- [canvas](https://npm.io/package/canvas.md) ^2.7.0
- [pdfjs-dist](https://npm.io/package/pdfjs-dist.md) 2.6.347
- [@react-pdf/renderer](https://npm.io/package/@react-pdf/renderer.md) ^1.6.15

## Recent versions

- 0.0.1 (latest) — 2021-05-13

## README

# react-pdf-testing-library

Set of helpers for `react-pdf` visual testing with `jest-image-snapshot`.

## Usage

```js
import { Resume } from '..'
import { renderDocument } from 'react-pdf-testing-library'

it('should work', async () => {
  const document = await renderDocument(<Resume />)

  expect(document.pagesNumber).toBe(2)
  expect(await document.page(0).imageSnapshot()).toMatchImageSnapshot()
  expect(await document.page(1).imageSnapshot()).toMatchImageSnapshot()
})
```

# API

## renderComponent

takes react-pdf component and size of page and returns helpers.

```js
const wrapper = await renderComponent(<Component />, { size: 'A5' })
```

> Size is optional. can be string (`A2`, `A3`, `A4`) or tuple (`[number, number]`) with width and height size in pixels. default value is `A4`

### imageSnapshot

returns raw png image of the component. 

```js
const wrapper = await renderComponent(<Component />)

expect(await wrapper.imageSnapshot()).toMatchImageSnapshot()
```

### containsLinkTo

checks that link with href exists in the component.

```js
const wrapper = await renderComponent(<Component />)

expect(await wrapper.containsLinkTo('https://example.com')).toBe(true)
```

### containsAnchorTo

checks that component contains goto construction with specified id.

```js
const wrapper = await renderComponent(<Component />)

expect(await wrapper.containsAnchorTo('#myDest')).toBe(true)
```

## renderDocument

takes react-pdf component or raw pdf and returns document helpers.

### pagesNumber

returns amount of pages in pdf.

```js
const document = await renderDocument(<Component />)

expect(document.pagesNumber).toBe(10)
```

### page

returns object with `imageSnapshot`, `containsLinkTo` and `containsAnchorTo` helpers for page with specified index, index starts from 0.

> helpers run over selected page

```js
const document = await renderDocument(<Component />)

expect(await document.page(0).imageSnapshot()).toMatchImageSnapshot()
expect(await document.page(1).containsAnchorTo('#myDest')).toBe(true)
expect(await document.page(2).containsLinkTo('https://example.com')).toBe(true)
```

## Build

Clone this repo, `cd` into it, make sure you’re using Node 12+, and then:

```sh
npm i
npm run build
```

## Run

Then run jest

```sh
npm test
```

## License

MIT

---
_Source: https://npm.io/package/react-pdf-testing-library · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
