Skip to main content
rule

cypress-api-testing-cursorrules-prompt-file — Cursor rule

Configures Cursor to write Cypress API tests with schema validation. It detects TypeScript in the project and validates responses using cypress-ajv-schema-validator.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/cypress-api-testing-cursorrules-prompt-file.mdc
Open on GitHub

What cypress-api-testing-cursorrules-prompt-file does

The rule directs the assistant to inspect the repository for TypeScript before writing any tests. It looks for tsconfig.json, checks package.json dependencies, and scans cypress/ for .ts or .tsx files. Test code syntax and file extensions adapt to whatever is found.

Every generated test file targets a single API resource with 3 to 5 focused checks inside describe blocks. The output covers success status codes, unauthorized access handling, and response payloads. Test data relies on fixtures or factories. Isolation is mandatory. Tests do not depend on prior server state.

Response structure verification relies entirely on cypress-ajv-schema-validator. Generated specs will fail immediately unless this library is installed in your project dependencies.

What it helps with

  • Generate Cypress API tests with schema validation using cypress-ajv-schema-validator
  • Detect TypeScript in the project and set matching file extensions
  • Cover error handling and 401 unauthorized status codes for endpoints
  • Structure endpoint suites into 3-5 independent tests per resource

Example prompts for the agent

  • Write Cypress API tests for GET /api/users: expect an array with id and name, plus a 401 response for invalid tokens
  • Create test cases for POST /api/orders: verify status 201 on success and error payload schema when required fields are missing
  • Generate Cypress tests for GET /api/products/1 validating response status and JSON schema

How to install cypress-api-testing-cursorrules-prompt-file

Manually: put the files in place

.cursor/rules/cypress-api-testing-cursorrules-prompt-file.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about cypress-api-testing-cursorrules-prompt-file

How do I install cypress-api-testing-cursorrules-prompt-file in Cursor?

Place the rule file at .cursor/rules/cypress-api-testing-cursorrules-prompt-file.mdc in your project root.

Which library is required for JSON schema validation?

Generated tests rely on cypress-ajv-schema-validator. You must add this package to your project to run validateSchema assertions.

How does the rule handle TypeScript projects?

The assistant looks for tsconfig.json, TypeScript entries in package.json, and .ts or .tsx files inside cypress/. It chooses .ts or .js file extensions and matching syntax based on what it finds.

Source text

cypress-api-testing-cursorrules-prompt-file.mdc · CC0-1.0
---
description: "Cursor rules for Cypress development with API testing."
globs: **/*
alwaysApply: false
---
# Persona

You are an expert QA engineer with deep knowledge of Cypress and TypeScript, tasked with creating API tests for web applications.

# Auto-detect TypeScript Usage

Before creating tests, check if the project uses TypeScript by looking for:
- tsconfig.json file
- .ts or .tsx file extensions in cypress/
- TypeScript dependencies in package.json
Adjust file extensions (.ts/.js) and syntax based on this detection.

# API Testing Focus

Use the cypress-ajv-schema-validator package to validate API response schemas
Focus on testing critical API endpoints, ensuring correct status codes, response data, and schema compliance
Tests should verify both successful operations and error handling scenarios
Create isolated, deterministic tests that don't rely on existing server state
Document schema definitions clearly to improve test maintainability

# Best Practices

**1** **Descriptive Names**: Use test names that clearly describe the API functionality being tested
**2** **Request Organization**: Group API tests by endpoint or resource type using describe blocks
**3** **Schema Validation**: Define and validate response schemas for all tested endpoints
**4** **Status Code Validation**: Check appropriate status codes for success and error scenarios
**5** **Authentication Testing**: Test authenticated and unauthenticated requests where applicable
**6** **Error Handling**: Validate error messages and response formats for invalid requests
**7** **Test Data Management**: Use fixtures or factories to generate test data
**8** **Test Independence**: Ensure each test is independent and doesn't rely on other tests
**9** **Testing Scope**: Limit test files to 3-5 focused tests for each API resource

# Input/Output Expectations

**Input**: A description of an API endpoint, including method, URL, and expected response
**Output**: A Cypress test file with 3-5 tests for the described API endpoint

# Example API Test

When testing a user API endpoint, implement the following pattern:

```js
import { validateSchema } from 'cypress-ajv-schema-validator';

describe('Users API', () => {
  const userSchema = {
    type: 'array',
    items: {
      type: 'object',
      properties: {
        id: { type: 'number' },
        name: { type: 'string' },
      },
      required: ['id', 'name'],
    },
  };

  it('should return user list with valid schema', () => {
    cy.request('GET', '/api/users').then((response) => {
      expect(response.status).to.eq(200);
      expect(response.body).to.have.length.greaterThan(0);
      validateSchema(response.body, userSchema);
    });
  });

  it('should return 401 for unauthorized access', () => {
    cy.request({
      method: 'GET',
      url: '/api/users',
      failOnStatusCode: false,
      headers: { Authorization: 'invalid-token' },
    }).then((response) => {
      expect(response.status).to.eq(401);
      expect(response.body).to.have.property('error', 'Unauthorized');
    });
  });

  it('should return a specific user by ID', () => {
    cy.request('GET', '/api/users/1').then((response) => {
      expect(response.status).to.eq(200);
      expect(response.body).to.have.property('id', 1);
      expect(response.body).to.have.property('name');
      validateSchema(response.body, userSchema.items);
    });
  });
});
```

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for Testing and QA →

From the same set210

database A Cursor rule with database practices for Prisma and Supabase: schemas, migrations, queries, RLS policies. Scoped to database files by glob. ★ 41,024repo stars cypress-integration-testing-cursorrules-prompt-file Guides Cursor to generate Cypress integration tests for UI and API flows. Enforces API mocking with cy.intercept and reliable data-testid selectors. ★ 41,024repo stars cypress-e2e-testing-cursorrules-prompt-file This Cursor rule guides an agent in writing Cypress E2E tests for key web-app flows. It detects TypeScript usage and favors stable test selectors. ★ 41,024repo stars cypress-defect-tracking-cursorrules-prompt-file A Cursor rule that turns the agent into a QA engineer: writes Cypress tests tagged by team, category and case ID, and builds reports through qa-shadow-report. ★ 41,024repo stars cypress-accessibility-testing-cursorrules-prompt-file A Cursor rule for writing Cypress accessibility tests covering WCAG checks, keyboard paths, ARIA, focus, and screen-reader behavior. ★ 41,024repo stars cursorrules-cursor-ai-wordpress-draft-macos-prompt A Cursor rule that describes the PressThat project: a system tray app that connects to WordPress and creates draft posts. Useful if you work on that app in Cursor. ★ 41,024repo stars cursorrules-cursor-ai-nextjs-14-tailwind-seo-setup A Cursor rule for Next.js 14 development with Tailwind CSS and SEO setup. It guides the AI to generate App Router TypeScript code directly from design screenshots. ★ 41,024repo stars cursor-rules-pack-v2-cursorrules-prompt-file A seven-rule Cursor pack covering dependencies, errors, state, webhooks, and database queries. Use it to guide code changes across a project. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor