Skip to content

enzyme -> RTL: convert App.test.js and util/omitProps - #476

Merged
cigamit merged 4 commits into
ctrliq:mainfrom
blaipr:feature/rtl-app-omitprops
Jun 18, 2026
Merged

enzyme -> RTL: convert App.test.js and util/omitProps#476
cigamit merged 4 commits into
ctrliq:mainfrom
blaipr:feature/rtl-app-omitprops

Conversation

@blaipr

@blaipr blaipr commented Jun 16, 2026

Copy link
Copy Markdown
Contributor
SUMMARY

Converts the root App.test.js and util/omitProps.test.js from 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 (App self-mounts its HashRouter/CompatRouter), and the ProtectedRoute login-redirect asserts via the navigation spy (useEffect-driven, awaited).

Behaviour and assertions are preserved.

ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • UI
ADDITIONAL INFORMATION

npm test for these files: 2 suites, 5 tests, all passing. ESLint clean (--no-ignore). No production code changed — test-only.

Note: with a full RTL mount, App drives the deep provider tree; dynamicActivate is held pending so the suite asserts the top-level loading shell (the faithful counterpart of the original shallow render) and avoids a pre-existing ConfigProvider mock warning unrelated to this change.

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.
@cigamit
cigamit requested a review from Copilot June 17, 2026 07:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

blaipr added 2 commits June 17, 2026 09:44
# 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).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread awx/ui/src/App.test.js Outdated
// mounted, the RTL counterpart of the original shallow length check.
const { container } = render(<App />);
expect(container).toHaveTextContent('Loading...');
jest.clearAllMocks();
@cigamit cigamit self-assigned this Jun 18, 2026
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
cigamit merged commit 2e445ed into ctrliq:main Jun 18, 2026
@blaipr

blaipr commented Jun 18, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants