Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/varugasu/cy-trpc

A dynamic Cypress Interceptor for tRPC routers
https://github.com/varugasu/cy-trpc

cypress trpc

Last synced: 3 months ago
JSON representation

A dynamic Cypress Interceptor for tRPC routers

Awesome Lists containing this project

README

        


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

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

### Create the stub

```ts
const trpcStub = stubTRPC()

trpcStub.hello.returns('interceptor')
```

### Test it!

```ts
const client = createTRPCProxyClient({
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