Description
Summary
Ideally react
is shipped with official test utilities instead of relying on third-party vendors.
Unfortunately it was decided to deprecatereact-test-renderer
.
As a consequence it isn't easy anymore to:
- write unit tests
- test React components independently of the target platform (React DOM, React Native, or any other custom renderer which is out there)
- test complex, deeply nested component trees
- shallow render
- make shallow snapshots
- to run tests FAST (in memory)
Regressions
@testing-library/react
is an integration testing library, promotes testing anti-patterns and completely ditches unit tests.
It is slow and requires a DOM or a mock like js-dom
.
Please refer to these resources for a comprehensive understanding of why unit tests are of high value:
Other critical voices from the community
- https://javascript.plainenglish.io/in-defense-of-shallow-rendering-5f627f7c155d
- https://blog.hao.dev/my-struggles-with-react-testing-library
References
react-test-renderer
is deprecated. A warning will fire whenever callingReactTestRenderer.create()
orReactShallowRender.render()
. Thereact-test-renderer
package will remain available on NPM but will not be maintained and may break with new React features or changes to React’s internals.
https://react.dev/warnings/react-test-renderer
react-test-renderer
is deprecated and no longer maintained. It will be removed in a future version. As of React 19, you will see a console warning when invokingReactTestRenderer.create()
.
https://www.npmjs.com/package/react-test-renderer/v/19.0.0-canary-8afa144bd-20240416?activeTab=readme#react-test-renderer-deprecated
Note: that affects any code using react-test-renderer
https://github.com/search?q=repo%3Ajestjs%2Fjest%20react-test-renderer&type=code