# jest-amp

> A Jest matcher to validate AMP markup

Latest version **1.3.1** (published 2021-01-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install jest-amp
pnpm add jest-amp
yarn add jest-amp
bun add jest-amp
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2021-01-15 |
| First published | 2020-05-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Alex Mendes |
| Maintainers | alexmendes |
| Keywords | jest, matcher, amp |

## Links

- npm: https://www.npmjs.com/package/jest-amp
- Repository: https://github.com/alexandermendes/jest-amp
- Homepage: https://github.com/alexandermendes/jest-amp#readme
- Issues: https://github.com/alexandermendes/jest-amp/issues
- npm.io page: https://npm.io/package/jest-amp

## Dependencies (3)

- [diffable-html](https://npm.io/package/diffable-html.md) ^4.0.0
- [amphtml-validator](https://npm.io/package/amphtml-validator.md) ^1.0.30
- [jest-matcher-utils](https://npm.io/package/jest-matcher-utils.md) ^25.5.0

## Recent versions

- 1.3.1 (latest) — 2021-01-15
- 1.2.0 — 2020-05-07
- 1.1.1 — 2020-05-06
- 1.1.0 — 2020-05-06
- 1.0.1 — 2020-05-04
- 1.0.0 — 2020-05-04

## README

# jest-amp

[![npm version](https://badge.fury.io/js/jest-amp.svg)](https://badge.fury.io/js/jest-amp)

A [Jest](https://jestjs.io/) matcher to validate [AMP](https://amp.dev/) markup.

This matcher works by wrapping HTML snippets in the minimum valid AMP HTML
document and running this through the [AMP validator](https://validator.ampproject.org/).

Note that this matcher currently requires an active internet connection to be able
to access the AMP validator.

## Installation

```
yarn add jest-amp -D
```

## Usage

```js
import { amp, toBeValidAmpHtml } from 'jest-amp';

expect.extend({ toBeValidAmpHtml });

it('is valid AMP HTML', async () => {
  const html = '<div>Hello, World</div>';

  expect(await amp(html)).toBeValidAmpHtml();
});
```

## Configuration

The `amp` function accepts an options object as the second argument.

### `script`

Inject any required script elements into the document head.

```js
import { amp } from 'jest-amp';

const ampMatcherOptions = {
  scripts: [
    {
      async: true,
      'custom-element': 'amp-list',
      src: 'https://cdn.ampproject.org/v0/amp-list-0.1.js',
    },
  ],
};

it('is valid AMP HTML', async () => {
  const html = '<amp-list src="example.com"></amp-list>';

  expect(await amp(html, ampMatcherOptions)).toBeValidAmpHtml();
});
```

Note that you can also use the alias `scriptTags`.

### `wrap`

Don't wrap the markup being tested in a boilerplate AMP document.

```js
import { amp } from 'jest-amp';

it('is valid AMP HTML', async () => {
  const html = '<amp-list src="example.com"></amp-list>';

  expect(await amp(html, { wrap: false })).toBeValidAmpHtml();
});
```

## Examples

Examples of tests written with Enzyme and React Testing Library can be found in
the [examples](https://github.com/alexandermendes/jest-amp/tree/master/examples)
directory.

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