---
url: /plugins/plugin-cypress.md
description: >-
  Generates a typed cy.request() wrapper per OpenAPI operation so your Cypress
  tests call the API through generated helpers and catch broken calls at compile
  time.
---

# @kubb/plugin-cypress

`@kubb/plugin-cypress` turns your OpenAPI operations into typed `cy.request()` wrappers, one helper per operation. Each helper types its path params, body, query, and response, so a broken API call fails at compile time instead of in the test runner. Use the helpers in `before` and `beforeEach` hooks to seed data, in custom commands, or in API-only tests.

Each helper takes its parameters as a single grouped options object shaped as `{ body, path, query, headers }`. Property names inside each group match the OpenAPI spec exactly, including snake\_case or quoted names, and Kubb forwards that object straight into `cy.request()` with no extra mapping. A helper resolves to the response body and its return type is `Cypress.Chainable<{Operation}Response>`.

## Installation

::: code-group

```shell [bun]
bun add -d @kubb/plugin-cypress
```

```shell [pnpm]
pnpm add -D @kubb/plugin-cypress
```

```shell [npm]
npm install --save-dev @kubb/plugin-cypress
```

```shell [yarn]
yarn add -D @kubb/plugin-cypress
```

:::

## Dependencies

This plugin depends on [`@kubb/plugin-ts`](/plugins/plugin-ts/) for the request, parameter, and response types it imports. Keep `pluginTs()` in the plugins array.

> \[!IMPORTANT]
> The generated requests need Cypress v13 or higher.

## Example

::: code-group

```typescript twoslash [kubb.config.ts]
import { defineConfig } from 'kubb'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginCypress } from '@kubb/plugin-cypress'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  plugins: [
    pluginTs(),
    pluginCypress({
      output: {
        path: './cypress',
        mode: 'directory',
        barrel: { type: 'named' },
        banner: '/* eslint-disable */',
      },
      group: {
        type: 'tag',
        name: ({ group }) => `${group}Requests`,
      },
    }),
  ],
})
```

```typescript [Using a generated helper]
import { getPetById } from '../gen/cypress/petRequests'

describe('Pet API', () => {
  it('returns the pet by id', () => {
    getPetById({ path: { petId: 1n } }).then((pet) => {
      expect(pet.id).to.eq(1n)
    })
  })
})
```

:::

## See also

* [Cypress](https://www.cypress.io/)
* [cy.request()](https://docs.cypress.io/api/commands/request)
* [@kubb/plugin-ts](/plugins/plugin-ts/)
* [Changelog](https://github.com/kubb-labs/plugins/blob/main/packages/plugin-cypress/CHANGELOG.md)
