test(core-trpc): cover the router-agnostic useTRPC delegation

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK
This commit is contained in:
2026-07-13 00:20:57 +02:00
parent 6e4e325bb3
commit beb9df4df2

View File

@@ -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"; import { useTRPC, TRPCProvider } from "./client";
describe("core-trpc client exports", () => { describe("core-trpc client exports", () => {
@@ -9,4 +20,10 @@ describe("core-trpc client exports", () => {
it("exports TRPCProvider component", () => { it("exports TRPCProvider component", () => {
expect(TRPCProvider).toBeTypeOf("function"); 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" });
});
}); });