-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Bundle react-test-renderer with AVA #1175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Sounds like an easy win. I don't like how big its dependency tree is though. It brings with it 2.5MB of mostly unused dependencies... |
What about projects that use JSX with another tool than React (Inferno, Preact, Snabbdom, ...)? |
Hmm, good point. Would be great if we had a universal |
Then |
On the other hand though, Here are the possible routes we can go:
This way would be the most comfortable from the user's perspective, but the most time consuming and expensive in terms of maintenance for us.
Least preferable way for both users and AVA, despite being the easiest solution. For diffs users would use libraries like chai-jsx.
This would make A shortcut could make it simpler to transform JSX for assertions: import renderer from 'react-test-renderer';
const render = tree => renderer.create(tree).toJSON();
test('jsx', t => {
t.jsxEqual(render(<HelloNewYork/>), render(<HelloSanFrancisco/>));
}); |
Can we use a Babel plugin to solve this? |
I don't think it can be reliably implemented, because we'd have to detect which library is imported (react/preact/inferno/etc) and import according In my opinion, we could do just fine with the third option for a while. Minimal maintenance, universal compatibility. |
Rephrasing yesterday's comment, now that I actually know what I meant to say…: Could we support Babel plugins that rewrite |
So steroids (babel plugins to transform JSX into JSON) are basically left for community to implement? Sure, why not? They can freely use any babel plugins in configuration. |
Closing this, since the issue is now resolved. |
Is there any reason why user has to manually import
react-test-renderer
and render their React tree "by hand"?We could bundle
react-test-renderer
and that test would become:...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 needreact-test-renderer
inside AVA either way.What do you think?
The text was updated successfully, but these errors were encountered: