ktmud opened a new issue #11688: URL: https://github.com/apache/incubator-superset/issues/11688
## [SIP] Proposal for adopting React Testing Library to test React components ### Motivation In Sept 2020, [React Testing Library](https://github.com/testing-library/react-testing-library) (RTL) has officially overtaken Enzyme as the most popular React testing library according to [NPM downloads](https://npmcharts.com/compare/@testing-library/react,enzyme?interval=7&log=false). While still wildly popular, Enzyme has been running behind in catching up with all the latest React trends. It still [doesn’t support](https://github.com/enzymejs/enzyme/issues/2011) the `useEffect` hook properly and has yet to fully support [React 17](https://github.com/enzymejs/enzyme/issues/2429). Besides having a more promising future and a more active community, RTL also introduces a new way of thinking in writing tests. It encourages developers to focus on what users see, as opposed to how the components are rendered. So instead of checking component props and states with fine-grained internal APIs, you check component outputs based on the expected user interactions. The official doc has more [explanation](https://testing-library.com/docs/react-testing-library/migrate-from-enzyme/). We believe this is the right way to go and will help us write stabler and more efficient tests with more confidence. With better support for simulating [user events](https://github.com/testing-library/user-event), we may even replace some Cypress tests with smaller scoped (and faster) RTL tests. ### Proposed Change We propose to introduce React Testing Library to Superset’s frontend testing toolkit and gradually migrate to it when possible. ### New dependencies `@testing-library/react` and `@testing-library/jest-dom` will be added to superset-frontend and superset-ui’s dependencies. ### Migration Plan and Compatibility 1. Add RTL to the codebase, try converting a couple of existing components to RTL. Hammer out global setups, etc. 2. Since there is no urgent need to migrate existing Enzyme tests, RTL and Enzyme will live side-by-side for as long as needed. 3. However, all new React component tests should be written with RTL to take advantage of its benefits described above. ### Rejected Alternatives * **Keep status quo**: the growing needs of better testing requires a better testing library. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
