testing

mgkyawzayya's avatarfrom mgkyawzayya

Write and manage tests using TDD with Pest (PHP), Vitest (React), and Playwright (E2E). Use when writingfeature tests, unit tests, component tests, or improving test coverage. EXCLUSIVE to testing-expert agent.

⭐1stars🔀0forks📁View on GitHub🕐Updated Dec 14, 2025⬇️1downloads

When & Why to Use This Skill

This Claude skill facilitates comprehensive Test-Driven Development (TDD) workflows across PHP (Pest), React (Vitest), and E2E (Playwright) environments. It streamlines the creation of unit, feature, and component tests while ensuring code reliability through a mandatory Red-Green-Refactor validation loop and automated test execution.

Use Cases

  • Implementing new features in Laravel applications using Pest to ensure business logic is validated through feature and unit tests.
  • Developing React components with Vitest to verify UI behavior and state management through isolated component testing.
  • Automating end-to-end (E2E) testing with Playwright to simulate user journeys and prevent regressions in web applications.
  • Improving existing codebase reliability by identifying untested paths and systematically increasing test coverage.
  • Debugging and fixing failing test suites by following a structured validation loop and utilizing framework-specific CLI commands.
nametesting
description|
allowed-toolsRead, Edit, Bash, Grep, Glob, Write

Testing

Exclusive to: testing-expert agent

Validation Loop (MANDATORY)

After writing or modifying tests, always verify:

composer test           # PHP tests pass
npm run test           # JS tests pass (if applicable)

TDD Feedback Loop:

  1. Write test → Verify it FAILS (Red)
  2. Implement minimal code → Verify it PASSES (Green)
  3. Refactor → Verify it still PASSES
  4. Repeat for edge cases

Instructions (TDD Workflow)

Step Action Verification
1 Write failing test composer test --filter=NewTest → FAILS
2 Implement minimal code composer test --filter=NewTest → PASSES
3 Refactor composer test → ALL PASS
4 Add edge cases Repeat steps 1-3

Pest Patterns (Laravel)

Feature Test

test('user can create post', function () {
    $user = User::factory()->create();
    
    $this->actingAs($user)
        ->post('/posts', ['title' => 'Test'])
        ->assertRedirect('/posts');
        
    $this->assertDatabaseHas('posts', ['title' => 'Test']);
});

Unit Test

test('generates slug from title', function () {
    expect((new SlugGenerator)->generate('Hello World'))
        ->toBe('hello-world');
});

Vitest Patterns (React)

describe('PostForm', () => {
    it('submits with valid data', async () => {
        const onSubmit = vi.fn();
        render(<PostForm onSubmit={onSubmit} />);
        
        await userEvent.type(screen.getByLabelText(/title/i), 'Test');
        await userEvent.click(screen.getByRole('button', { name: /submit/i }));
        
        expect(onSubmit).toHaveBeenCalled();
    });
});

Test Commands

# Laravel
composer test
php artisan test --filter=PostTest
php artisan test --coverage

# React
npm run test
npm run test:watch
npm run test:coverage

Examples

  • "Write tests for PostController"
  • "Add unit tests for this service"
  • "Fix failing test"