Skip to content
Official v5.0.0-beta.100 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
27.4k / mo
Stars
4
Bundle size
120.8 kB
Updated
today

@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 { 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',
        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: 1 } }).then((pet) => {
      expect(pet.id).to.eq(1)
    })
  })
})

See also