jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.12k stars 6.44k forks source link

[Docs]: `react-test-renderer` deprecated #15150

Open AndyOGo opened 3 months ago

AndyOGo commented 3 months ago

Page(s)

Description

react-test-renderer is deprecated.

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

mrazauskas commented 3 months ago

The React 19 RC Upgrade Guide says:

We recommend migrating your tests to @testing-library/react or @testing-library/react-native for a modern and well supported testing experience.

So I guess Jest's docs and examples should be updated accordingly. @AndyOGo would you be up to putting together a PR?

AndyOGo commented 3 months ago

Thanks for your quick reply @mrazauskas

Well @testing-library/react is a library to write integration tests, it doesn't support shallow snapshot testing nor snapshot diffing.

IMHO these testing approaches pose an anti-pattern and promote bad practices, completely invalidating the first layer of the testing pyramid - unit tests. https://martinfowler.com/articles/practical-test-pyramid.html

mrazauskas commented 3 months ago

So perhaps both pages (Testing React Apps and Testing React Native Apps) should be simply removed?

I see that https://jestjs.io/docs/testing-frameworks already includes @testing-library/react under the Testing ReactJS components with Jest entry.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

AndyOGo commented 2 months ago

@facebook-github-bot this isn't resolved yet

SimenB commented 1 month ago

Happy to just delete the articles, if you're up for sending a PR

AndyOGo commented 1 month ago

@SimenB The deprecation of react-test-renderer affects more than just those doc pages.

IMHO someone who knows this repo well should take care to analyze and to carry out all of the required changes. A quick search reveals at least something of what has to be done - it seems pretty-format has some implicit or explicit dependency too (just a guess): :https://github.com/search?q=repo%3Ajestjs%2Fjest%20react-test-renderer&type=code

github-actions[bot] commented 4 weeks ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

AndyOGo commented 4 weeks ago

+1