webapp-testing

Guide webapp testing with integration, unit, and snapshot tests in SonarQube.

11|15|Updated Dec 6, 2024
One-click install
npx skills add https://github.com/SonarSource/sonarqube-webapp --skill webapp-testing-sonarsource
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: webapp-testing
Source: https://github.com/SonarSource/sonarqube-webapp/tree/main/.claude/skills/webapp-testing
Command: npx skills add https://github.com/SonarSource/sonarqube-webapp --skill webapp-testing-sonarsource

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance on writing effective and maintainable tests for web applications, ensuring code quality and reliability.

Core Features & Use Cases

  • Testing Philosophy: Understand the principles of testing use cases and functional aspects over implementation details.
  • Naming Conventions: Learn the standard file naming patterns for integration and unit tests.
  • Testing Layers: Differentiate between Integration Tests, Unit Tests, and Snapshots, with best practices for each.
  • Mocking: Implement smart mocks for API calls and understand how to use them effectively in tests.
  • Critical Rules: Adhere to essential testing rules like using await selector.find() and preferring toBeInTheDocument.
  • Use Case: A new developer joins the team and needs to understand how to write tests for a new feature in the SonarQube webapp, including setting up mocks and following established patterns.

Quick Start

Follow the guidelines in this skill to write a new integration test for a webapp component.

Frequently Asked Questions about webapp-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write integration tests for webapp components?

Webapp integration tests should focus on testing use cases and functional aspects rather than implementation details. You should follow standard file naming patterns and use established libraries like `testSelector` to find elements, ensuring your tests remain robust and maintainable.

What is the best way to mock API calls in frontend testing?

The best way to mock API calls in frontend testing is by implementing smart mocks using the `msw` library. This approach allows you to effectively intercept and simulate network requests, ensuring your integration tests run reliably without hitting actual backend endpoints.

When should I use findBy instead of waitFor in Jest tests?

You should prefer `findBy` over `waitFor` in Jest tests because `findBy` queries automatically wait for elements to appear in the DOM. Adhering to this critical testing rule prevents flaky tests and simplifies asynchronous DOM testing logic.

How do I differentiate between unit tests and integration tests for webapps?

Unit tests isolate and verify individual functions or components, while integration tests evaluate multiple parts working together, such as a component interacting with the DOM. Both testing layers are essential, and you should use standard naming conventions to distinguish them.

Does webapp testing guidance cover snapshot testing best practices?

Yes, webapp testing guidance covers snapshot testing alongside unit and integration tests. It provides best practices for configuring these tests to ensure they capture meaningful UI changes without becoming brittle or requiring constant manual updates.