ni -D cy-trpc
# pnpm
pnpm add -D cy-trpc
# yarn
yarn add -D cy-trpc
# npm
npm i -D cy-trpc
const t = initTRPC.create({ allowOutsideOfServer: true })
const router = t.router({
hello: t.procedure.query(() => 'world'),
})
const trpcStub = stubTRPC<Router>()
trpcStub.hello.returns('interceptor')
const client = createTRPCProxyClient<Router>({
links: [httpLink({ url: '/api/trpc' })],
})
const result = await client.hello.query()
expect(result).equal('interceptor')
For now, having a intercept is enough for my use case. But I am still figuring out how to make it generic as possible and support several use cases for mocking/stubbing tRPC.
Things on the roadmap:
- Support tRPC config
transformersolved in 0.0.4- base url
- links
- Pass options to
cy.intercept
- Mock tRPC client