Socket
Book a DemoInstallSign in
Socket

jest-serializer-html-string

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-serializer-html-string

A better Jest snapshot serializer for plain html strings

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
753
-0.13%
Maintainers
1
Weekly downloads
 
Created
Source

jest-serializer-html-string NPM version Build Status

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

Example

Given:

function renderElem(props) {
	return `<body>
				<div class="home active">
					<h1><img src="${ props.img }" alt="Foo"/></h1><div>Hello</div>
					<p><span class="something">Hey</span>
					<img src="${ props.img }" /></p>
				</div>
			</body>
	`;
}

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

Produces beautified snapshot:

<body>
  <div class="home active">
    <h1>
      <img src="/foo.png" alt="Foo" />
    </h1>
    <div>Hello</div>
    <p>
      <span class="something">Hey</span>
      <img src="/foo.png" />
    </p>
  </div>
</body>

Setup

Install from npm:

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

Add it to your Jest config:

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

Please refer to the Jest snapshotSerializers config docs if you need more info.

License

MIT © Ruy Adorno

Keywords

jest

FAQs

Package last updated on 12 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts