Skip to main content
rule

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

Guides Cursor to generate Cypress integration tests for UI and API flows. Enforces API mocking with cy.intercept and reliable data-testid selectors.

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

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

This rule configures Cursor as a QA engineer writing Cypress integration tests. The model inspects tsconfig.json or dependencies in package.json to automatically switch between TypeScript and JavaScript syntax. It prioritizes critical user journeys and state transitions across components.

Network calls must be stubbed using cy.intercept to validate both success paths and error responses. The rule requires selectors based on data-testid attributes rather than fragile CSS classes. It also restricts each feature to 3–5 focused tests.

Visual styling assertions are strictly banned. If you need CSS layout verification, this prompt will ignore it.

What it helps with

  • mock API responses with cy.intercept in Cypress
  • generate integration tests covering UI and API interaction
  • enforce data-testid attributes for reliable element selection
  • write test scenarios for form validation errors

Example prompts for the agent

  • Write Cypress integration tests for user registration handling both 200 and 400 API responses
  • Generate 3 to 5 tests for the checkout flow using data-testid selectors and cy.intercept

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

Manually: put the files in place

.cursor/rules/cypress-integration-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-integration-testing-cursorrules-prompt-file

How to install cypress-integration-testing-cursorrules-prompt-file in Cursor?

Create .cursor/rules/cypress-integration-testing-cursorrules-prompt-file.mdc in your project root and paste the rule content into that file.

What does cypress-integration-testing-cursorrules-prompt-file do?

It guides Cursor to generate Cypress integration tests, stub API requests with cy.intercept, and target elements using data-testid attributes.

Does this rule support TypeScript?

Yes. Cursor inspects tsconfig.json or package.json to determine whether to write tests in TypeScript or JavaScript.

Source text

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

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

# Auto-detect TypeScript Usage

Check for TypeScript in the project through tsconfig.json or package.json dependencies.
Adjust syntax based on this detection.

# Integration Testing Focus

Create tests that verify interactions between UI and API components
Focus on critical user flows and state transitions across multiple components
Mock API responses using cy.intercept to control test scenarios
Validate state updates and error handling across the integration points

# Best Practices

**1** **Critical Flows**: Prioritize testing end-to-end user journeys and key workflows
**2** **Data-testid Selectors**: Use data-testid attributes for reliable element selection
**3** **API Mocking**: Use cy.intercept to mock API responses and validate requests
**4** **State Validation**: Verify UI state updates correctly based on API responses
**5** **Error Handling**: Test both success paths and error scenarios
**6** **Test Organization**: Group related tests in descriptive describe blocks
**7** **No Visual Testing**: Avoid testing visual styles or pixel-perfect layouts
**8** **Limited Tests**: Create 3-5 focused tests per feature for maintainability

# Example Integration Test

```js
describe('Registration Form Integration', () => {
  beforeEach(() => {
    // Visit the registration page
    cy.visit('/register');
    
    // Mock the API response
    cy.intercept('POST', '/api/register', (req) => {
      if (req.body.email && req.body.email.includes('@')) {
        req.reply({ 
          statusCode: 200, 
          body: { message: 'Registration successful' }
        });
      } else {
        req.reply({ 
          statusCode: 400, 
          body: { error: 'Invalid email format' }
        });
      }
    }).as('registerRequest');
  });

  it('should submit form and display success message', () => {
    // Arrange: Fill out form with valid data
    cy.get('[data-testid="name-input"]').type('John Doe');
    cy.get('[data-testid="email-input"]').type('[email protected]');
    cy.get('[data-testid="password-input"]').type('Password123');
    
    // Act: Submit the form
    cy.get('[data-testid="register-button"]').click();
    
    // Wait for API request to complete
    cy.wait('@registerRequest').its('request.body').should('include', {
      name: 'John Doe',
      email: '[email protected]'
    });
    
    // Assert: Verify success message is displayed
    cy.get('[data-testid="success-message"]')
      .should('be.visible')
      .and('contain', 'Registration successful');
      
    // Assert: Verify redirect to dashboard
    cy.url().should('include', '/dashboard');
  });

  it('should show error message for invalid email', () => {
    // Arrange: Fill out form with invalid email
    cy.get('[data-testid="name-input"]').type('John Doe');
    cy.get('[data-testid="email-input"]').type('invalid-email');
    cy.get('[data-testid="password-input"]').type('Password123');
    
    // Act: Submit the form
    cy.get('[data-testid="register-button"]').click();
    
    // Wait for API request to complete
    cy.wait('@registerRequest');
    
    // Assert: Verify error message is displayed
    cy.get('[data-testid="error-message"]')
      .should('be.visible')
      .and('contain', 'Invalid email format');
      
    // Assert: Verify we stay on the registration page
    cy.url().should('include', '/register');
  });

  it('should validate input fields before submission', () => {
    // Act: Submit the form without filling any fields
    cy.get('[data-testid="register-button"]').click();
    
    // Assert: Form validation errors should be displayed
    cy.get('[data-testid="name-error"]').should('be.visible');
    cy.get('[data-testid="email-error"]').should('be.visible');
    cy.get('[data-testid="password-error"]').should('be.visible');
    
    // Assert: No API request should be made
    cy.get('@registerRequest.all').should('have.length', 0);
  });
});
```

# TypeScript Example

```ts
// Define types for the API responses
interface RegisterSuccessResponse {
  message: string;
}

interface RegisterErrorResponse {
  error: string;
}

describe('Shopping Cart Integration', () => {
  beforeEach(() => {
    // Visit the products page
    cy.visit('/products');
    
    // Mock the products API
    cy.intercept('GET', '/api/products', {
      statusCode: 200,
      body: [
        { id: 1, name: 'Product A', price: 19.99, inStock: true },
        { id: 2, name: 'Product B', price: 29.99, inStock: true },
        { id: 3, name: 'Product C', price: 39.99, inStock: false }
      ]
    }).as('getProducts');
    
    // Mock the cart API
    cy.intercept('POST', '/api/cart/add', (req) => {
      const productId = req.body.productId;
      if (productId === 3) {
        req.reply({
          statusCode: 400,
          body: { error: 'Product out of stock' }
        });
      } else {
        req.reply({
          statusCode: 200,
          body: { 
            message: 'Product added to cart',
            cartCount: 1
          }
        });
      }
    }).as('addToCart');
  });

  it('should add in-stock product to cart', () => {
    // Wait for products to load
    cy.wait('@getProducts');
    
    // Verify products are displayed
    cy.get('[data-testid="product-item"]').should('have.length', 3);
    
    // Add first product to cart
    cy.get('[data-testid="product-item"]').first()
      .find('[data-testid="add-to-cart"]')
      .click();
    
    // Wait for API request to complete
    cy.wait('@addToCart').its('request.body').should('deep.equal', {
      productId: 1,
      quantity: 1
    });
    
    // Verify cart count is updated
    cy.get('[data-testid="cart-count"]').should('contain', '1');
    
    // Verify success message
    cy.get('[data-testid="cart-notification"]')
      .should('be.visible')
      .and('contain', 'Product added to cart');
  });

  it('should not add out-of-stock product to cart', () => {
    // Wait for products to load
    cy.wait('@getProducts');
    
    // Try to add out-of-stock product (Product C)
    cy.get('[data-testid="product-item"]').eq(2)
      .find('[data-testid="add-to-cart"]')
      .click();
    
    // Wait for API request to complete
    cy.wait('@addToCart');
    
    // Verify error message
    cy.get('[data-testid="error-notification"]')
      .should('be.visible')
      .and('contain', 'Product out of stock');
    
    // Verify cart count is not updated
    cy.get('[data-testid="cart-count"]').should('contain', '0');
  });
});

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

Similar IDE rules

All IDE rules for Testing and QA →

From the same set210

dragonruby-best-practices-cursorrules-prompt-file A Cursor rule that sets Ruby coding style for DragonRuby Game Toolkit: naming, file structure, error handling. ★ 41,024repo stars docker Cursor rule enforcing production Docker practices. Generates minimal, hardened containers with non-root users, layer caching, and pinned base images. ★ 41,024repo stars deno-integration-techniques-cursorrules-prompt-fil This rule gives Cursor context for Deno automation scripts and workflows. It fits repositories built around the @findhow packages. ★ 41,024repo stars 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-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-api-testing-cursorrules-prompt-file Configures Cursor to write Cypress API tests with schema validation. It detects TypeScript in the project and validates responses using cypress-ajv-schema-validator. ★ 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

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