enzyme -> RTL: convert App.test.js and util/omitProps - #476
Merged
Conversation
Migrate the root App test and the omitProps util test off enzyme onto React Testing Library. omitProps' forwarded/omitted props are asserted via real DOM attributes; App's loading shell and the ProtectedRoute login redirect are asserted via the rendered DOM and navigation spy. Behaviour and assertions are preserved.
# Conflicts: # awx/ui/src/App.test.js
awx/ui/node_modules was committed as a self-referential symlink; .gitignore only excludes the directory contents, not the symlink itself. Untrack it (also removes a cross-PR collision with another open PR that carried the same symlink).
| // mounted, the RTL counterpart of the original shallow length check. | ||
| const { container } = render(<App />); | ||
| expect(container).toHaveTextContent('Loading...'); | ||
| jest.clearAllMocks(); |
clearAllMocks() does not restore jest.spyOn spies. With resetMocks:true (package.json), a leftover useSession spy can leak into subsequent tests — or reruns with --testNamePattern that skip the trailing restoreAllMocks — as a reset spy that returns undefined. Restore all mocks in afterEach and drop the ad-hoc per-test cleanup.
cigamit
approved these changes
Jun 18, 2026
Contributor
Author
|
Thanks for the catch. Fixed in 7f79dd0. I moved the cleanup into an afterEach that calls jest.restoreAllMocks() and dropped the per-test jest.clearAllMocks() / replaceSpy.mockRestore() calls. Now the jest.spyOn spies are actually restored after every test, so a leftover useSession spy can't leak into a later test (or a partial rerun) as a reset spy returning undefined. All three tests still pass. |
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 root
App.test.jsandutil/omitProps.test.jsfrom enzyme to React Testing Library, continuing the enzyme → RTL migration.omitProps— forwarded props now assert as real DOM attributes on the rendered element; omitted props assert absent.App— the loading shell renders (Appself-mounts itsHashRouter/CompatRouter), and theProtectedRoutelogin-redirect asserts via the navigation spy (useEffect-driven, awaited).Behaviour and assertions are preserved.
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
npm testfor these files: 2 suites, 5 tests, all passing. ESLint clean (--no-ignore). No production code changed — test-only.Note: with a full RTL mount,
Appdrives the deep provider tree;dynamicActivateis held pending so the suite asserts the top-level loading shell (the faithful counterpart of the originalshallowrender) and avoids a pre-existingConfigProvidermock warning unrelated to this change.