Skip to content

test(NetworkBanner): fix undefined renderWithNetwork helper - #640

Open
uche001-dev wants to merge 1 commit into
Sorokit:mainfrom
uche001-dev:fix/network-switch-error-boundary-qrcode
Open

test(NetworkBanner): fix undefined renderWithNetwork helper#640
uche001-dev wants to merge 1 commit into
Sorokit:mainfrom
uche001-dev:fix/network-switch-error-boundary-qrcode

Conversation

@uche001-dev

Copy link
Copy Markdown
Contributor

Related to #523 (not closing it — see the disclosure comment on that issue for why #523's actual behavior is already fixed on main)

Summary

While verifying #523 (network switching) was already resolved, found that 3 of NetworkBanner.test.tsx's 11 tests were calling a renderWithNetwork helper that was never defined anywhere in the file:

ReferenceError: renderWithNetwork is not defined

This PR:

  • Adds the missing renderWithNetwork(name, element?) helper — mocks useSorokit to return a synthetic network built from just a name (the other NetworkInfo fields are irrelevant to NetworkBanner, which only ever reads network.name), then renders the given element (or a bare <NetworkBanner /> by default).
  • Fixes the third broken test, which asserted client.network.getNetwork had been called — NetworkBanner never touches a client at all, it only reads network straight from context, so that assertion could never have passed against the real component even with the helper defined. Replaced with an assertion of what the component actually does (renders nothing when active="network"), and renamed it since it was an exact duplicate of an existing test's title.

Why this and not #523/#522/#519 themselves

Checked all three of my assigned issues in this repo before starting any work:

I didn't want to open a no-op PR against any of the three original issues, but this test-infra gap was concrete, small, and directly tied to #523's own acceptance criteria ("active network badge shows the correct network"), so it seemed worth fixing rather than just disclosing.

Verification

  • npx vitest run src/components/NetworkBanner.test.tsx — 11/11 passing (was 8/11).
  • npx eslint src/components/NetworkBanner.test.tsx — clean (ran --fix once for import ordering per the project's simple-import-sort rule).
  • npx tsc --noEmit — clean across the whole project.

Related to Sorokit#523

While verifying Sorokit#523 (network switching) was already fixed on main, found
that 3 of NetworkBanner.test.tsx's 11 tests were calling a renderWithNetwork
helper that was never defined anywhere in the file, failing with
ReferenceError: renderWithNetwork is not defined.

Adds the missing helper: mocks useSorokit to return a synthetic network
built from just a name (rpcUrl/passphrase/horizonUrl are irrelevant to
NetworkBanner, which only ever reads network.name), then renders the given
element (or a bare <NetworkBanner /> by default).

Also fixes the third broken test, which asserted client.network.getNetwork
had been called — NetworkBanner never touches a client at all, it only
reads network from context directly, so that assertion could never have
passed against the real component. Replaced with an assertion of what the
component actually does (renders nothing when active="network", exercised
here against an arbitrary/unknown network to keep it independent of the
synchronous mainnet/testnet case already covered above), and renamed it
to stop duplicating the title of the existing synchronous version of the
same case.

Verification: all 11 tests in this file pass; npx eslint clean (after
--fix reordered imports per the project's import-sort rule); npx tsc
--noEmit clean across the whole project.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mock-client.ts is dead code duplicated by inline adapter in main.tsx causing diverged mocks

1 participant