Rax renderer for snapshot testing.
$ npm install --save-dev rax-test-renderer
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();
});