rax-test-renderer

1.1.0 • Public • Published

rax-test-renderer npm Dependency Status Known Vulnerabilities

Rax renderer for snapshot testing.

Install

$ npm install --save-dev rax-test-renderer

Usage

This package provides an renderer that can be used to render Rax components to pure JavaScript objects, without depending on the DOM or a native mobile environment:

import {createElement} from 'rax';
import renderer from 'rax-test-renderer';

const tree = renderer.create(
  <Link page="https://example.com/">Example</Link>
);

console.log(tree.toJSON());
// { tagName: 'A',
//   attributes: { href: 'https://example.com/' },
//   children: [ 'Example' ] }

You can also use Jest's snapshot testing feature to automatically save a copy of the JSON tree to a file and check in your tests that it hasn't changed: http://facebook.github.io/jest/blog/2016/07/27/jest-14.html.

import {createElement} from 'rax';
import renderer from 'rax-test-renderer';

test('Link renders correctly', () => {
  const tree = renderer.create(
    <Link page="https://example.com">Example</Link>
  ).toJSON();
  expect(tree).toMatchSnapshot();
});

Readme

Keywords

none

Package Sidebar

Install

npm i rax-test-renderer

Weekly Downloads

126

Version

1.1.0

License

BSD-3-Clause

Unpacked Size

28.8 kB

Total Files

23

Last publish

Collaborators

  • zeroling
  • wintercn
  • yuanyan
  • yacheng
  • rax-publisher