Skip to content
Official v5.0.0-beta.103 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
24.4k / mo
Stars
5
Bundle size
125.0 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 }. 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

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 { 
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
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