Jest test for tRPC route

Hi guys, I have been using Jest to test tRPC routes in a project like this:
import { expect, it } from "@jest/globals";
import { inferProcedureInput } from "@trpc/server";
import { prisma } from "../../../../server/db";
import { AppRouter, appRouter } from "../../root";

it("tests the example hello router", async () => {
const caller = appRouter.createCaller({ session: null, prisma: prisma });

type Input = inferProcedureInput<AppRouter["example"]["hello"]>;

const input: Input = {
text: "test",
};

const result = await caller.example.hello(input);

expect(result).toStrictEqual({ greeting: "Hello test"})
});
import { expect, it } from "@jest/globals";
import { inferProcedureInput } from "@trpc/server";
import { prisma } from "../../../../server/db";
import { AppRouter, appRouter } from "../../root";

it("tests the example hello router", async () => {
const caller = appRouter.createCaller({ session: null, prisma: prisma });

type Input = inferProcedureInput<AppRouter["example"]["hello"]>;

const input: Input = {
text: "test",
};

const result = await caller.example.hello(input);

expect(result).toStrictEqual({ greeting: "Hello test"})
});
With "@trpc/server": "^10.9.0" - everything works as expected. However in a new project using the t-3 App router from npm create t3-app@latest which has "@trpc/server": "^10.43.6",: 'createCaller' is deprecated.ts(6385) The types file for router.d.ts say to use t.createCallerFactory(router) instead and links to the docs: https://trpc.io/docs/server/server-side-calls But I am struggling to make this work within the t-3 set up. Has anyone else had this problem? Or any suggestions on how to fix it/ work around it? Thanks
Server Side Calls | tRPC
You may need to call your procedure(s) directly from the same server they're hosted in, createCallerFactory() can be used to achieve this. This is useful for server-side calls and for integration testing of your tRPC procedures.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server