如何使用jest和react测试库模拟TRPC客户端进行单元和集成测试?
rekjcdws1#
我们需要围绕使用查询方法的组件创建一个TRPCTestingWrapper。
export const TRPCWrapper = ({ children }: { children: ReactNode }) => { const [queryClient] = useState(() => new QueryClient()); const [trpcClient] = useState(() => trpc.createClient({ links: [ httpBatchLink({ url: platformSpecificLocalHostUrl, fetch: async (input, init?) => { const fetch = getFetch(); return fetch(input, { ...init, // credentials: "include", }); }, }), ], }) ); return ( <trpc.Provider client={trpcClient} queryClient={queryClient}> <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> </trpc.Provider> ); };
1条答案
按热度按时间rekjcdws1#
我们需要围绕使用查询方法的组件创建一个TRPCTestingWrapper。