Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate away from Enzyme tests in favor of React Testing Library #166

Closed
Tracked by #195
adamstankiewicz opened this issue May 24, 2023 · 3 comments
Closed
Tracked by #195
Labels
epic Large unit of work, consisting of multiple tasks maintenance Routine upkeep necessary for the health of the platform

Comments

@adamstankiewicz
Copy link
Member

adamstankiewicz commented May 24, 2023

We recently noticed during our attempt to ensure Paragon is compatible with React 18 that using Enzyme with this React version for JavaScript tests will not be compatible, as Enzyme is largely no longer maintained. See https://dev.to/wojtekmaj/enzyme-is-dead-now-what-ekl for additional context, but the short of it is:

  • Enzyme is no longer actively maintained.
  • It does not support React hooks.
  • There is no and will be no support for React 18.

The recommended alternative to Enzyme is React Testing Library. Migrating between these test frameworks will not be as trivial as drop-in replacements; the mindsets in using Enzyme vs. React Testing Library are different: with Enzyme, you can (and sometimes have to) rely on implementation details of what you're testing whereas with React Testing Library, you're encouraged more to think about testing from a user's perspective (e.g., is there an element with this matching {text | a11y role | data-testid | etc) rendered. From there, you can access the underlying DOM node to make further assertions about class names, etc. if needed.

Related, there is a proposal to officially deprecate Enzyme through Open edX and amend the OEP-11 that recommends the use of Enzyme to suggest the use of React Testing Library instead: openedx/open-edx-proposals#487

@arbrandes
Copy link

I checked frontend-template-application, and for better or worse there's no enzyme in there. (Maybe because there are no real tests. :P) So, for now, the only urgent thing to do is change OEP-11.

@adamstankiewicz
Copy link
Member Author

I checked frontend-template-application, and for better or worse there's no enzyme in there. (Maybe because there are no real tests. :P) So, for now, the only urgent thing to do is change OEP-11.

Yep, that sounds about right 😃

@arbrandes
Copy link

Closing as duplicate of openedx/public-engineering#195.

@github-project-automation github-project-automation bot moved this from Backlog to Closed in Frontend Working Group Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic Large unit of work, consisting of multiple tasks maintenance Routine upkeep necessary for the health of the platform
Projects
Status: Closed
Development

No branches or pull requests

2 participants