From beb9df4df2c173866c7bdcd3d3ec7d98bd6493bd Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Mon, 13 Jul 2026 00:20:57 +0200 Subject: [PATCH] test(core-trpc): cover the router-agnostic useTRPC delegation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The router-agnostic refactor turned useTRPC from a destructured const into a wrapper function; its body was unexercised, dropping client.ts below the 80% coverage floor. Stub the tRPC context factory and assert useTRPC() delegates to the shared proxy — client.ts back to 100%. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK --- packages/core-trpc/src/client.test.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/core-trpc/src/client.test.ts b/packages/core-trpc/src/client.test.ts index e998a06..9d879d2 100644 --- a/packages/core-trpc/src/client.test.ts +++ b/packages/core-trpc/src/client.test.ts @@ -1,4 +1,15 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect, vi } from "vitest"; + +// Stub the tRPC context factory so useTRPC() can run outside a React render: +// the real context.useTRPC() requires a mounted TRPCProvider. The stubbed +// proxy lets us exercise the router-agnostic delegation (client.ts:useTRPC). +vi.mock("@trpc/tanstack-react-query", () => ({ + createTRPCContext: () => ({ + TRPCProvider: () => null, + useTRPC: () => ({ __proxy: "trpc-options-proxy" }), + }), +})); + import { useTRPC, TRPCProvider } from "./client"; describe("core-trpc client exports", () => { @@ -9,4 +20,10 @@ describe("core-trpc client exports", () => { it("exports TRPCProvider component", () => { expect(TRPCProvider).toBeTypeOf("function"); }); + + it("useTRPC delegates to the underlying router-agnostic tRPC proxy", () => { + // The generic is a compile-time-only cast; at runtime it returns whatever + // the shared context proxy yields. + expect(useTRPC()).toEqual({ __proxy: "trpc-options-proxy" }); + }); });