Officialv5.0.4MITkubb >=5.0.0node >=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
Stijn Van Hulle

Stijn Van Hulle

@stijnvanhulle

Downloads
29.1K/ mo
Stars
8
Bundle size
138.5 kB
Updated
14h ago

@kubb/plugin-cypress generates typed cy.request() helpers from OpenAPI operations. Helpers take grouped { body, path, query, headers } parameters and return the response body as Cypress.Chainable<{Operation}Response>. Parameter names match the spec.

Installation

bun add -d @kubb/plugin-cypress

Dependencies

Add pluginTs for request and response types. Generated helpers require Cypress v13 or higher.

Example

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' } }),
  ],
})
pet.cy.ts
import { getPetById } from '../src/gen/cypress/getPetById'

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

Documentation

See also