Beta You're reading the docs for Kubb v5, which is currently in beta. View the stable v4 docs
Skip to content
Official v5.0.0-beta.85 MIT kubb >=5.0.0 node >=22

@kubb/plugin-cypress

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.

cypresse2e-testingapi-testingtest-generationcodegenopenapi
Downloads
30.9k / mo
Stars
3
Bundle size
177.9 kB
Updated
2d ago

@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 }, with camelCase property names. The request still sends the original parameter names from the spec, and Kubb writes that mapping for you. A helper resolves to the response body and its return type is Cypress.Chainable<{Operation}Response>.

Installation

shell
bun add -d @kubb/plugin-cypress@beta
shell
pnpm add -D @kubb/plugin-cypress@beta
shell
npm install --save-dev @kubb/plugin-cypress@beta
shell
yarn add -D @kubb/plugin-cypress@beta

Dependencies

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

Example

typescript
import {  } from 'kubb'
import {  } from '@kubb/plugin-ts'
import {  } from '@kubb/plugin-cypress'

export default ({
  : { : './petStore.yaml' },
  : { : './src/gen' },
  : [
    (),
    ({
      : {
        : './cypress',
        : { : 'named' },
        : '/* eslint-disable */',
      },
      : {
        : 'tag',
        : ({  }) => `${}Requests`,
      },
    }),
  ],
})
typescript
import { getPetById } from '../gen/cypress/petRequests'

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

See also