An open API service indexing awesome lists of open source software.

https://github.com/ruyadorno/jest-serializer-html-string

A better Jest snapshot serializer for plain html strings
https://github.com/ruyadorno/jest-serializer-html-string

html javascript jest js markup nodejs serializer snapshot string test

Last synced: over 1 year ago
JSON representation

A better Jest snapshot serializer for plain html strings

Awesome Lists containing this project

README

          

# jest-serializer-html-string [![NPM version](https://badge.fury.io/js/jest-serializer-html-string.svg)](https://npmjs.org/package/jest-serializer-html-string) [![Build Status](https://travis-ci.org/ruyadorno/jest-serializer-html-string.svg?branch=master)](https://travis-ci.org/ruyadorno/jest-serializer-html-string)

A slightly better Jest snapshot serializer for working with strings containing rendered html.

## Example

### Given:

```js
function renderElem(props) {
return `


Foo


Hello

Hey




`;
}

expect(renderElem({ img: '/foo.png' })).toMatchSnapshot();
```

### Produces beautified snapshot:

```html



Foo


Hello


Hey


```

## Setup

### Install from npm:

```sh
npm install --save-dev jest-serializer-html-string
```

### Add it to your Jest config:

```json
"jest": {
"snapshotSerializers": ["jest-serializer-html-string"]
}
```

Please refer to the [Jest snapshotSerializers config docs](https://facebook.github.io/jest/docs/configuration.html#snapshotserializers-array-string) if you need more info.

## License

MIT © [Ruy Adorno](http://ruyadorno.com)