From cae8f4a3181c56977ea1dc0669bb290ab474d868 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Fri, 18 Sep 2026 00:32:17 -0400 Subject: [PATCH] test(mobile): hold the rendered tree and the captured signal in boxes Assigning to a `let` inside a callback leaves it narrowed to `null`, which the harness was answering with two type assertions. A one-property box is a checked type and the casting gate no longer has anything to report. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb --- .../use-mobile-web-bundle-probe.test.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mobile/src/diagnostics/use-mobile-web-bundle-probe.test.tsx b/mobile/src/diagnostics/use-mobile-web-bundle-probe.test.tsx index e3df8d39fa2..a9a71bc4309 100644 --- a/mobile/src/diagnostics/use-mobile-web-bundle-probe.test.tsx +++ b/mobile/src/diagnostics/use-mobile-web-bundle-probe.test.tsx @@ -63,7 +63,8 @@ type ProbeHarness = { async function renderProbe(hostId: string | null): Promise { let latest: ReturnType | null = null - let renderer: ReactTestRenderer | null = null + // A box, not a `let`: assigning inside the callback leaves a `let` narrowed to `null`. + const rendered: { tree: ReactTestRenderer | null } = { tree: null } function Probe(): null { latest = useMobileWebBundleProbe(hostId) @@ -71,9 +72,8 @@ async function renderProbe(hostId: string | null): Promise { } await act(async () => { - renderer = create(createElement(RpcClientProvider, null, createElement(Probe))) + rendered.tree = create(createElement(RpcClientProvider, null, createElement(Probe))) }) - const mounted = renderer as ReactTestRenderer | null const read = () => { if (!latest) { throw new Error('probe did not render') @@ -94,7 +94,7 @@ async function renderProbe(hostId: string | null): Promise { }, unmount: async () => { await act(async () => { - mounted?.unmount() + rendered.tree?.unmount() }) } } @@ -182,18 +182,17 @@ describe('useMobileWebBundleProbe', () => { }) it('aborts the run it started when the screen goes away', async () => { - let captured: AbortSignal | null = null + const captured: { signal: AbortSignal | null } = { signal: null } fetchMock.mockImplementation((args: { signal?: AbortSignal }) => { - captured = args.signal ?? null + captured.signal = args.signal ?? null return new Promise(() => {}) }) const probe = await renderProbe(HOST.id) await probe.run() - const signal = captured as AbortSignal | null - expect(signal?.aborted).toBe(false) + expect(captured.signal?.aborted).toBe(false) await probe.unmount() - expect(signal?.aborted).toBe(true) + expect(captured.signal?.aborted).toBe(true) }) })