Skip to content

Conversation

@JamieMagee
Copy link
Contributor

Summary

  • Replace deprecated Enzyme testing library with React Testing Library (RTL)
  • Migrate all 25 test files from Enzyme patterns to RTL patterns
  • Fix Redux mock store shapes and add required props for connected components

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

  • Removed: enzyme, enzyme-adapter-react-16, jest-enzyme
  • Added: @testing-library/react@12, @testing-library/jest-dom@5, @testing-library/user-event@14

Test Files Migrated

  • Updated setupTests.js to use RTL's jest-dom matchers
  • Converted all component tests from shallow/mount + wrapper.find() to render + screen queries
  • Added explicit import React from 'react' where needed (React 16 requirement)
  • Fixed mock store shapes to include required nested properties (filterList.list, componentList.transformedList, etc.)
  • Added mock history object for router-dependent components

Notes

  • 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

Testing

All 101 tests pass across 31 test suites.

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.
@netlify
Copy link

netlify bot commented Jan 16, 2026

Deploy Preview for blissful-goodall-fa23f6 ready!

Name Link
🔨 Latest commit 7d77865
🔍 Latest deploy log https://app.netlify.com/projects/blissful-goodall-fa23f6/deploys/696ab4cb6df4490007f36eb8
😎 Deploy Preview https://deploy-preview-1097--blissful-goodall-fa23f6.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

Copilot AI left a 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.js to 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.
@JamieMagee
Copy link
Contributor Author

Addressed Copilot Review Feedback

I've pushed a commit addressing the review comments:

1. Fixed filename typo

  • Renamed PageBrowe.test.jsPageBrowse.test.js

2. Added LicensePickerUtils unit tests

  • Created LicensePickerUtils.test.js with 17 test cases covering:
    • parseLicense() - parsing simple, AND, OR, NOASSERTION, and nested expressions
    • toString() - converting rules back to license strings, including plus modifiers and exceptions
    • isValidExpression() - validating license expressions
    • createRules() - creating new rule conjunctions
    • createGroup() - creating nested license groups
    • removeRule() - removing rules from expressions

3. Added zero score display assertion

  • ScoreRenderer.test.js now verifies that 0 is displayed in the badge for zero scores

4. Added modal button assertions to VersionSelector

  • Tests now verify OK/Cancel buttons are present and that OK is disabled when no selection is made
  • Note: Component name display depends on async API calls in componentDidMount, which would require mocking the API

5. Added table rendering tests to FileList

  • Tests now verify the table structure renders with file data

Regarding removed tests (FileList filtering, FOSSA parsing)

The removed tests for internal methods (filterFiles, filterValues, isFossaInput, getListFromFossaPackage) were testing implementation details rather than user behavior. This aligns with RTL's philosophy of testing components from a user perspective. The license manipulation logic is now properly tested via the extracted LicensePickerUtils pure functions.

Copy link

Copilot AI left a 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.

Copy link
Contributor

@jamesiri jamesiri left a 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

@jamesiri jamesiri merged commit abd5609 into master Jan 16, 2026
12 checks passed
@jamesiri jamesiri deleted the jamiemagee/migrate-enzyme-to-rtl branch January 16, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants