- Remove unused @trpc/tanstack-react-query dependency - Document renderWithProviders tRPC provider omission (boundary constraint) - Implement deep merge in defineFactory (preserves nested sibling keys) - Document httpBatchLink<any> rationale in mock-trpc.ts - Align core-testing's own vitest.config with safety defaults (mockReset, unstubGlobals) - Add createMockTrpcClient usage example to AGENTS.md Reviewer: superpowers:code-reviewer (Task 1 of Plan 7). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import type { PropsWithChildren, ReactElement } from "react";
|
|
import { render } from "@testing-library/react";
|
|
import type { RenderResult } from "@testing-library/react";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
|
|
export interface RenderOptions {
|
|
queryClient?: QueryClient;
|
|
}
|
|
|
|
// Wraps the given UI with QueryClientProvider only.
|
|
// This helper intentionally omits a TRPCProvider. Adding one would require importing
|
|
// AppRouter from @repo/core-api, which violates the tooling→core-composition boundary rule.
|
|
// For components that need tRPC in the render tree, the consumer must:
|
|
// 1. Wire their own TRPCProvider (from their app's tRPC client setup).
|
|
// 2. Pass a client built with createMockTrpcClient as the tRPC client.
|
|
export function renderWithProviders(
|
|
ui: ReactElement,
|
|
options: RenderOptions = {},
|
|
): RenderResult & { queryClient: QueryClient } {
|
|
const queryClient =
|
|
options.queryClient ??
|
|
new QueryClient({
|
|
defaultOptions: {
|
|
queries: { retry: false },
|
|
mutations: { retry: false },
|
|
},
|
|
});
|
|
|
|
const Wrapper = ({ children }: PropsWithChildren) => (
|
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
);
|
|
|
|
const result = render(ui, { wrapper: Wrapper });
|
|
return Object.assign(result, { queryClient });
|
|
}
|