/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/tests/server/rawFetch.test.tsx
57 строк
1 KB
Alex / KATT
chore: test refactor (#6958)
24 сен 2025, 08:03
Не верифицирован
24 сен 2025, 08:03
466a924
Код
Авторство
О чём код?
import { testServerAndClientResource } from '@trpc/client/__tests__/testClientResource'; import { initTRPC } from '@trpc/server'; import { z } from 'zod'; const factory = () => { const t = initTRPC.context().create(); const router = t.router({ myQuery: t.procedure .input( z .object({ name: z.string(), }) .optional(), ) .query(({ input }) => { return input?.name ?? 'default'; }), myMutation: t.procedure .input( z.object({ name: z.string(), }), ) .mutation(async ({ input }) => { return { input }; }), }); return testServerAndClientResource(router); }; test('batching with raw batch', async () => { await using ctx = factory(); const { httpUrl } = ctx; { const res = await fetch( `${httpUrl}/myQuery?batch=1&input=${JSON.stringify({ '0': { name: 'alexdotjs' }, })}`, { headers: { 'content-type': 'application/json', }, }, ); const json: any = await res.json(); expect(json[0]).toHaveProperty('result'); expect(json[0].result).toMatchInlineSnapshot(` Object { "data": "alexdotjs", } `); } });