Commit c77f0db
[Management][Es Ui Shared][Kbn Management] Migrate Enzyme to RTL (elastic#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>1 parent 002cae9 commit c77f0db
19 files changed
Lines changed: 1145 additions & 1102 deletions
File tree
- src/platform
Lines changed: 78 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
30 | 44 | | |
31 | 45 | | |
32 | 46 | | |
33 | | - | |
34 | | - | |
35 | | - | |
| 47 | + | |
36 | 48 | | |
37 | | - | |
| 49 | + | |
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
41 | | - | |
42 | | - | |
43 | 53 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
51 | 60 | | |
52 | 61 | | |
53 | 62 | | |
54 | 63 | | |
55 | | - | |
56 | | - | |
57 | | - | |
| 64 | + | |
58 | 65 | | |
59 | | - | |
| 66 | + | |
60 | 67 | | |
61 | 68 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 69 | + | |
65 | 70 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 71 | + | |
| 72 | + | |
71 | 73 | | |
72 | 74 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 75 | + | |
| 76 | + | |
78 | 77 | | |
79 | | - | |
80 | | - | |
81 | | - | |
| 78 | + | |
82 | 79 | | |
83 | 80 | | |
0 commit comments