Skip to content

varugasu/cy-trpc

Repository files navigation

Cypress tRPC Interceptor

A dynamic Cypress Interceptor for tRPC routers.

NPM version MIT License

Installation

ni -D cy-trpc
# pnpm
pnpm add -D cy-trpc
# yarn
yarn add -D cy-trpc
# npm
npm i -D cy-trpc

No need to run a server

Define your router

const t = initTRPC.create({ allowOutsideOfServer: true })
const router = t.router({
  hello: t.procedure.query(() => 'world'),
})

Create the stub

const trpcStub = stubTRPC<Router>()

trpcStub.hello.returns('interceptor')

Test it!

const client = createTRPCProxyClient<Router>({
  links: [httpLink({ url: '/api/trpc' })],
})

const result = await client.hello.query()
expect(result).equal('interceptor')

Unstable!

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
    • transformer solved in 0.0.4
    • base url
    • links
  • Pass options to cy.intercept
  • Mock tRPC client

About

A dynamic Cypress Interceptor for tRPC routers

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published