Skip to content

[React 19] revive react-test-renderer #30551

Open
@AndyOGo

Description

@AndyOGo

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

References

react-test-renderer is deprecated. A warning will fire whenever calling ReactTestRenderer.create() or ReactShallowRender.render(). The react-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 invoking ReactTestRenderer.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

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