TypeScript
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.editorconfig
.gitattributes
.gitignore
.travis.yml
changelog.md
license
package.json
readme.md
tsconfig.json
yarn.lock

readme.md

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