enzyme -> RTL: convert the hooks test suites - #475
Merged
Conversation
Migrate src/hooks tests (useSelected, useExpanded, useModal, useToast, useRequest, useWsTemplates, useDebounce) off enzyme onto React Testing Library. Each hook is exercised via a small harness that exposes its result through a const ref/DOM node (RTL 12 has no renderHook); mutators run inside act(). Behaviour and assertions are preserved.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR continues the UI test migration from Enzyme to React Testing Library by converting multiple src/hooks test suites to RTL-style harness components while preserving existing behavior and assertions.
Changes:
- Migrated several hook test suites (
useSelected,useExpanded,useModal,useToast,useRequest/useDeleteItems,useWsTemplates,useDebounce) from Enzyme to RTL. - Replaced Enzyme wrapper-based assertions with DOM queries (
screen) and ref-based result capture patterns compatible with the repo’s RTL setup. - Updated websocket hook tests to assert updates via rendered JSON output and
waitFor()rather than Enzymewrapper.update().
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| awx/ui/src/hooks/useWsTemplates.test.js | Migrates websocket hook tests to RTL with a JSON-output harness and waitFor() assertions. |
| awx/ui/src/hooks/useToast.test.js | Converts useToast/Toast tests to RTL using result capture and DOM-based assertions. |
| awx/ui/src/hooks/useSelected.test.js | Rewrites selection hook tests to RTL with a ref-backed harness and act() state updates. |
| awx/ui/src/hooks/useRequest.test.js | Converts request hooks tests to RTL harnesses; needs follow-up fixes to correctly await async updates in act(). |
| awx/ui/src/hooks/useModal.test.js | Migrates modal state hook tests to RTL with ref-backed harness and act(). |
| awx/ui/src/hooks/useExpanded.test.js | Migrates expanded-state hook tests to RTL with ref-backed harness and updated test naming. |
| awx/ui/src/hooks/useDebounce.test.js | Converts debounce hook test to RTL and wraps timer advancement in act(). |
Comment on lines
42
to
46
| await act(async () => { | ||
| wrapper.find('TestInner').invoke('request')(); | ||
| latest().request(); | ||
| }); | ||
| wrapper.update(); | ||
| expect(wrapper.find('TestInner').prop('result')).toEqual({ data: 'foo' }); | ||
| expect(latest().result).toEqual({ data: 'foo' }); | ||
| }); |
Comment on lines
57
to
66
| await act(async () => { | ||
| wrapper.find('TestInner').invoke('request')(); | ||
| latest().request(); | ||
| }); | ||
| wrapper.update(); | ||
| expect(wrapper.find('TestInner').prop('isLoading')).toEqual(true); | ||
| expect(latest().isLoading).toEqual(true); | ||
| await act(async () => { | ||
| resolve({ data: 'foo' }); | ||
| }); | ||
| wrapper.update(); | ||
| expect(wrapper.find('TestInner').prop('isLoading')).toEqual(false); | ||
| expect(wrapper.find('TestInner').prop('result')).toEqual({ data: 'foo' }); | ||
| expect(latest().isLoading).toEqual(false); | ||
| expect(latest().result).toEqual({ data: 'foo' }); | ||
| }); |
Comment on lines
74
to
78
| await act(async () => { | ||
| wrapper.find('TestInner').invoke('request')(); | ||
| latest().request(); | ||
| }); | ||
| wrapper.update(); | ||
| expect(makeRequest).toHaveBeenCalledTimes(1); | ||
| }); |
Comment on lines
109
to
+113
| await act(async () => { | ||
| wrapper.find('TestInner').invoke('request')(); | ||
| latest().request(); | ||
| }); | ||
| wrapper.update(); | ||
| expect(wrapper.find('TestInner').prop('result')).toEqual({ data: 'foo' }); | ||
| expect(wrapper.find('TestInner').prop('error')).toEqual(null); | ||
| expect(latest().result).toEqual({ data: 'foo' }); | ||
| expect(latest().error).toEqual(null); |
Await the request() promise inside act() so the resulting state updates flush within act (no not-wrapped-in-act warnings); for the isLoading test capture the pending request and await it in the act() that resolves makeRequest.
Contributor
Author
|
Thanks for the review. Pushed a commit: await the request() promise inside act() so the resulting state updates flush within act, and for the isLoading case capture the pending request and await it in the act() that resolves the request. |
cigamit
approved these changes
Jun 18, 2026
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
Converts the
src/hookstest suites from enzyme to React Testing Library, continuing the enzyme → RTL migration.Files migrated off enzyme onto RTL:
useSelected,useExpanded,useModal,useToast,useRequest(+useDeleteItems),useWsTemplates,useDebounce.Each hook is exercised via a small harness component that exposes its result through a
constref object / adata-testidJSON node (RTL 12 has norenderHook); state-mutating methods run insideact(), and the websocket hook usesjest-websocket-mock(mirroring the converteduseWs*screen hooks). Behaviour and assertions are preserved.ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
npm testforsrc/hooks: 7 suites, 35 tests, all passing. ESLint clean (--no-ignore).Note: the result is captured via property mutation on a
constobject (result.current = useHook(...)) rather than reassigning alet— the latter tripsreact-hooks/globals(eslint-plugin-react-hooks v7). Also fixed a copy-pastedescribe('useSelected')label / mismatched test names inuseExpanded.test.js. No production code changed — test-only.