reactjs/rfcs

[React-Test-Renderer] Making React Testing Library Interact Smoothly with Enzyme's shallows/mounts.

ITenthusiasm opened this issue · 0 comments

I was wondering how feasible it would be to make the react-test-renderer play nicely with enzyme? The create() method seems to work on enzyme's shallowed and mounted components just fine. The only issue is that the warning, Warning: Each child in a list should have a unique "key" prop. See https://fb.me/react-warning-keys for more information., keeps popping up whenever create() is used this way. (I'm assuming this is occurring because the library wasn't made with enzyme in mind.)

If it would be feasible to change react-test-renderer so that it could also interact with enzyme without the warnings, that would be awesome!

My use case involves my use of enzyme and styled-components. In an integration test, I'm trying to verify that a certain style rule of a child component is adhered to after an event is fired off. To test this, I have to fire the event, then use enzyme's find() to grab the relevant child component. After this, I use jest-styled-components's toHaveStyleRule(), which in turn only plays nicely with output from react-test-renderer's toJSON(). So I have to use create() on the shallowed/mounted component, use toJSON, and then do the style assertion. Again, the test passes just fine, but the warning I mentioned earlier pops up. I figure while the working functionality is present, might as well remove the errors and consider it a new feature.

(Or, if people are aware of alternatives, feel free to mention them.)