[Management][Es Ui Shared][Kbn Management] Migrate Enzyme to RTL#238764
Merged
kapral18 merged 7 commits intoelastic:mainfrom Oct 21, 2025
Merged
[Management][Es Ui Shared][Kbn Management] Migrate Enzyme to RTL#238764kapral18 merged 7 commits intoelastic:mainfrom
kapral18 merged 7 commits intoelastic:mainfrom
Conversation
Contributor
|
Pinging @elastic/kibana-management (Team:Kibana Management) |
d861da7 to
c6fe547
Compare
sabarasaba
reviewed
Oct 20, 2025
Member
sabarasaba
left a comment
There was a problem hiding this comment.
Awesome job @kapral18! This is one of those PRs that I read and go like: "why didnt we do this before?!!" 🥳
src/platform/plugins/shared/es_ui_shared/public/request/use_request.test.helpers.tsx
Outdated
Show resolved
Hide resolved
...lugins/shared/es_ui_shared/static/forms/hook_form_lib/components/form_data_provider.test.tsx
Show resolved
Hide resolved
This commit migrates 17 test files from Enzyme to React Testing Library (RTL), removing dependencies on enzyme and the registerTestBed test utility. Changes include: - Replaced enzyme's shallow/mount with RTL's render - Migrated from registerTestBed to direct RTL rendering for hook and component tests - Updated test utilities to use @testing-library/react and @testing-library/user-event - Fixed async testing patterns with waitFor and proper act() wrapping - Resolved fake timers compatibility issues with userEvent - Added proper event handling with fireEvent and userEvent where appropriate - Updated all snapshots to reflect RTL rendering output Affected test files: - query_input.test.tsx - cron_editor.test.tsx - view_api_request_flyout.test.tsx - use_request.test.ts and helpers - form_data_provider.test.tsx - use_array.test.tsx - use_field.test.tsx (component and hook tests) - use_multi_fields.test.tsx - use_form.test.tsx - use_form_data.test.tsx - use_form_is_modified.test.tsx - landing.test.tsx All tests are now passing with the new RTL implementation.
These exports are no longer used after migrating all tests from Enzyme to RTL. Only keeping getRandomString export which is still used in test files.
c6fe547 to
1f2c593
Compare
Contributor
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Count of Enzyme imports
History
|
NicholasPeretti
pushed a commit
to NicholasPeretti/kibana
that referenced
this pull request
Oct 27, 2025
…stic#238764) ## Summary This PR migrates the first batch of test files from Enzyme to React Testing Library (RTL) as part of the effort to remove Enzyme dependencies from the Kibana codebase. Addresses elastic#22260 ### Migration Details **Enzyme → RTL API Changes:** - Replaced `shallow()` / `mount()` with RTL's `render()` - Replaced `shallowWithIntl` / `mountWithIntl` with `renderWithI18n` - Replaced `.find()` with `screen.getByTestId()` / `screen.getByLabelText()` - Replaced `.simulate()` with `userEvent` interactions - Removed `wrapper.update()` calls (unnecessary in RTL) - Removed Enzyme type imports (`ShallowWrapper`, `ReactWrapper`) **Modern Testing Patterns:** - Added Jest modern fake timers setup (`jest.useFakeTimers()`) - Configured `userEvent.setup({ advanceTimers: jest.advanceTimersByTime })` - Replaced `waitFor()` polling with direct assertions using timer control - Implemented "Start → Flush → Await" pattern for async operations with internal timers - Added proper `act()` wrapping for state-changing operations - All tests now use async/await for user interactions **TypeScript Fixes:** - Fixed context provider type issues in `landing.test.tsx` - Ensured all required `AppDependencies` props are provided - Removed unused imports and fixed linting issues **Snapshot Updates:** - Updated all snapshots to reflect RTL's rendering output format ## Testing - ✅ All migrated tests pass locally - ✅ Zero console warnings (verified with `NODE_ENV=development`) - ✅ TypeScript compilation successful - ✅ ESLint passes with no errors - ✅ Snapshots updated and validated ## Performance Improvements Tests are now faster and more deterministic: - No polling with `waitFor()` - direct assertions with timer control - Fake timers eliminate real-time waiting - More reliable in CI environments ## Checklist - [x] Removed all Enzyme dependencies from test files - [x] Added modern fake timer setup - [x] Configured userEvent with timer advancement - [x] Replaced waitFor() with timer control - [x] All tests pass with zero warnings - [x] TypeScript compiles without errors - [x] ESLint passes - [x] Snapshots updated - [x] Helper files migrated where needed ## Next Steps This is the first batch. Subsequent batches will continue migrating the remaining test files listed in issue elastic#222608. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This was referenced Oct 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR migrates the first batch of test files from Enzyme to React Testing Library (RTL) as part of the effort to remove Enzyme dependencies from the Kibana codebase.
Addresses #222608
Migration Details
Enzyme → RTL API Changes:
shallow()/mount()with RTL'srender()shallowWithIntl/mountWithIntlwithrenderWithI18n.find()withscreen.getByTestId()/screen.getByLabelText().simulate()withuserEventinteractionswrapper.update()calls (unnecessary in RTL)ShallowWrapper,ReactWrapper)Modern Testing Patterns:
jest.useFakeTimers())userEvent.setup({ advanceTimers: jest.advanceTimersByTime })waitFor()polling with direct assertions using timer controlact()wrapping for state-changing operationsTypeScript Fixes:
landing.test.tsxAppDependenciesprops are providedSnapshot Updates:
Testing
NODE_ENV=development)Performance Improvements
Tests are now faster and more deterministic:
waitFor()- direct assertions with timer controlChecklist
Next Steps
This is the first batch. Subsequent batches will continue migrating the remaining test files listed in issue #222608.