Skip to content

Bundle react-test-renderer with AVA #1175

@vadimdemedes

Description

@vadimdemedes

Is there any reason why user has to manually import react-test-renderer and render their React tree "by hand"?

import test from 'ava';
import React from 'react';
import renderer from 'react-test-renderer';

test('snapshots', t => {
  const tree = renderer.create(<h1>Test</h1>).toJSON();
  t.snapshot(tree);
});

We could bundle react-test-renderer and that test would become:

import test from 'ava';
import React from 'react';

test('snapshots', t => {
  const tree = <h1>Test</h1>;
  t.snapshot(tree);
});

...which is cleaner and nicer, imo.

Main reason for it is to also allow magic assert to do diffing on snapshots. Because trees in snapshots are not shallowly rendered (full trees are saved instead), we can't use react-element-to-jsx-string module, so we need react-test-renderer inside AVA either way.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions