preact-to-json
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

preact-to-json

Build Status npm devDependencies

Convert Preact components to JSON.

Note: This library currently only supports shallow rendering. If you need full (non-shallow) rendering, check out nathancahill/preact-render-to-json.

Installation

$ yarn add --dev preact-to-json

Usage

// ES6
import render from 'preact-to-json'
 
// ES5
const { render } = require('preact-to-json')
 
// With Jest
describe('Component', () => {
  it('renders', () => {
    const Component = () => (<a href="//google.com">Google</a>)
    const element = render(<Component />)
 
    expect(element).toMatchSnapshot()
  })
})
 
// test.snap
exports[`Component renders 1`] = `
<a
  href="//google.com"
>
  Google
</a>
`;

Change Log

Full Change Log

v1.1.2 (2018-01-26)

  • [7201875d00] - Handle when null/undefined children are rendered (Neil Kistner)

License

MIT © Neil Kistner

Package Sidebar

Install

npm i preact-to-json

Weekly Downloads

0

Version

1.1.2

License

MIT

Last publish

Collaborators

  • wyze