-
Notifications
You must be signed in to change notification settings - Fork 31
Migrate test suite from Enzyme to React Testing Library #1097
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
Conversation
Enzyme has been deprecated and is no longer maintained, making it incompatible with newer versions of React. This migration replaces Enzyme with React Testing Library (RTL), which is the recommended testing library for React applications. Changes: - Replace enzyme, enzyme-adapter-react-16, and jest-enzyme with @testing-library/react@12, @testing-library/jest-dom@5, and @testing-library/user-event@14 - Update setupTests.js to use RTL's jest-dom matchers instead of Enzyme configuration - Migrate all 25 test files from Enzyme patterns (shallow, mount, wrapper.find) to RTL patterns (render, screen, userEvent) - Add explicit React imports to test files (required for React 16 JSX) - Fix Redux mock store shapes to include required nested properties for connected components (filterList.list, componentList.transformedList) - Add mock history object for router-dependent components RTL v12 is used as it's the last version supporting React 16. Once React is upgraded, RTL can be updated to the latest version.
✅ Deploy Preview for blissful-goodall-fa23f6 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request migrates the test suite from the deprecated Enzyme testing library to React Testing Library (RTL). The migration updates all 25 test files to use RTL patterns (render + screen queries) instead of Enzyme patterns (shallow/mount + wrapper.find). The changes include updating test setup configuration, fixing Redux mock store structures, and adding proper provider wrapping for connected components.
Changes:
- Removed Enzyme dependencies (
enzyme,enzyme-adapter-react-16,jest-enzyme) and added RTL dependencies (@testing-library/react@12,@testing-library/jest-dom@5,@testing-library/user-event@14) - Updated
setupTests.jsto configure RTL's jest-dom matchers instead of Enzyme - Migrated all test files from Enzyme patterns to RTL patterns with proper Redux/Router provider wrapping
Reviewed changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/setupTests.js | Replaced Enzyme configuration with RTL jest-dom setup |
| src/components/tests/PageDefinitions.test.js | Migrated to RTL with Redux/Router providers, removed obsolete tests |
| src/components/tests/PageContributions.test.js | Converted to RTL with proper store mock structure |
| src/components/tests/PageBrowe.test.js | Added history mock prop and RTL rendering |
| src/components/tests/InlineEditor.test.js | Updated to use RTL render with Provider wrapper |
| src/components/tests/FileList.test.js | Simplified test, removed complex filter tests |
| src/components/tests/FacetsRenderer.test.js | Added test case with values |
| src/components/tests/ComponentList.test.js | Added WindowProvider and new assertions |
| src/components/tests/App.test.js | Migrated to screen queries with proper role assertions |
| src/components/Navigation/Ui/tests/*.test.js | Converted 8 UI component tests to RTL patterns |
| src/components/LicensePicker/tests/*.test.js | Simplified tests, removed internal implementation testing |
| package.json | Updated dependencies: removed Enzyme packages, added RTL v12 packages |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix filename typo: PageBrowe.test.js -> PageBrowse.test.js - Add LicensePickerUtils.test.js with unit tests for license expression parsing, toString conversion, rule creation, and rule removal - Add zero score display assertion to ScoreRenderer.test.js - Add modal button assertions to VersionSelector.test.js - Add table rendering tests to FileList.test.js The removed tests for FOSSA input parsing and internal filtering methods tested implementation details rather than user behavior. The license rule manipulation logic is now tested via the LicensePickerUtils pure functions. RTL encourages testing components from a user perspective rather than testing internal methods directly.
Addressed Copilot Review FeedbackI've pushed a commit addressing the review comments: 1. Fixed filename typo
2. Added LicensePickerUtils unit tests
3. Added zero score display assertion
4. Added modal button assertions to VersionSelector
5. Added table rendering tests to FileList
Regarding removed tests (FileList filtering, FOSSA parsing)The removed tests for internal methods ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 26 out of 27 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jamesiri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a testing expert but this looks fine to me
Summary
Why
Enzyme has been deprecated and is no longer maintained, making it incompatible with newer versions of React. React Testing Library is the recommended testing approach that encourages testing components the way users interact with them.
Changes
Dependencies
enzyme,enzyme-adapter-react-16,jest-enzyme@testing-library/react@12,@testing-library/jest-dom@5,@testing-library/user-event@14Test Files Migrated
setupTests.jsto use RTL's jest-dom matchersshallow/mount+wrapper.find()torender+screenqueriesimport React from 'react'where needed (React 16 requirement)filterList.list,componentList.transformedList, etc.)historyobject for router-dependent componentsNotes
Testing
All 101 tests pass across 31 test suites.