question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bundle react-test-renderer with AVA

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
jfmengelscommented, Jan 11, 2017

What about projects that use JSX with another tool than React (Inferno, Preact, Snabbdom, …)?

0reactions
vadimdemedescommented, Jan 19, 2017

Closing this, since the issue is now resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactJS : setup ava for testing react components
Ava.js is a futuristic test runner, which runs your tests concurrently. This will force you to write tests without depending on a global ......
Read more >
Test Renderer - React
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM...
Read more >
Testing the Bejeezus out of React Native Apps with AVA
This article shows you how to use AVA to test your React Native app. It covers all the 3rd party libraries required to...
Read more >
Testing React Native components in Node with react ... - Medium
The react-test-renderer package makes it convenient to test components outside of their native environment (e.g. on an iOS/Android device ...
Read more >
Testing React Components with AVA - Semaphore CI
We'll connect our React components to the Redux store, test them using AVA and Airbnb's Enzyme, and see how React makes it easy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found