Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/anthonkendel/jest-serializer-pug

HTML to Pug Jest snapshot serializer
https://github.com/anthonkendel/jest-serializer-pug

anthonkendel jest jest-snapshot-serializer pug snapshot snapshot-testing

Last synced: 19 days ago
JSON representation

HTML to Pug Jest snapshot serializer

Awesome Lists containing this project

README

        

# [`jest-serializer-pug`](https://github.com/anthonkendel/jest-serializer-pug)

Pug Jest snapshot serializer

[![latest git version](https://img.shields.io/github/v/tag/anthonkendel/jest-serializer-pug?label=version)](https://github.com/anthonkendel/jest-serializer-pug)
[![latest npm version](https://img.shields.io/npm/v/jest-serializer-pug)](https://www.npmjs.com/package/jest-serializer-pug)
[![license](https://img.shields.io/github/license/anthonkendel/jest-serializer-pug)](https://github.com/anthonkendel/jest-serializer-pug/blob/master/LICENSE)

## Installation

### Requirements

- `node` >= v10
- `npm` >= v5
- `jest` >= v22

```bash
npm install --save-dev jest-serializer-pug
```

## Usage

Once the `jest-serializer-pug` package is installed, you can use it by specifying the `jest-serializer-pug` serializer for the [`snapshotSerializers`](https://jestjs.io/docs/en/configuration#snapshotserializers-arraystring) property in the [Jest configuration](https://jestjs.io/docs/en/configuration).

```js
{
"snapshotSerializers": ["jest-serializer-pug"]
}
```

The serializer support values that are of type [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) or [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element). Internally it uses [`html2pug`](https://github.com/izolate/html2pug) to convert HTML to Pug template.

## Example

### html

```html



Username









This username is available



Message







I agree to the terms and conditions






Yes



No




Submit


Cancel



```

### pug

```pug
div
.field
label.label Username
.control.has-icons-left.has-icons-right
input.input.is-success(type="text", placeholder="Text input", value="bulma")
span.icon.is-small.is-left
i.fas.fa-user
span.icon.is-small.is-right
i.fas.fa-check
p.help.is-success This username is available
.field
label.label Message
.control
textarea.textarea(placeholder="Textarea")
.field
.control
label.checkbox
input(type="checkbox")
|
I agree to the
a(href="#") terms and conditions
.field
.control
label.radio
input(type="radio", name="question")
|
Yes

label.radio
input(type="radio", name="question")
|
No

.field.is-grouped
.control
button.button.is-link Submit
.control
button.button.is-link.is-light Cancel
```

## Contributing

If you want to contribute and make our project better, your help is very welcome.

## License

[MIT © anthonkendel](https://choosealicense.com/licenses/mit/)