Fähigkeiten testing-patterns
📦

testing-patterns

Sicher

Write Better Jest Tests

Auch verfügbar von: 0xDarkMatter,0xDarkMatter,CleanExpo,ChrisWiles

This skill provides ready-to-use Jest testing patterns including factory functions, custom render utilities, and mocking strategies that help developers write maintainable, DRY tests following TDD principles.

Unterstützt: Claude Codex Code(CC)
🥉 75 Bronze
1

Die Skill-ZIP herunterladen

2

In Claude hochladen

Gehe zu Einstellungen → Fähigkeiten → Skills → Skill hochladen

3

Einschalten und loslegen

Teste es

Verwendung von "testing-patterns". Create a factory function for user data

Erwartetes Ergebnis:

```typescript
interface User {
id: string;
name: string;
email: string;
role: 'admin' | 'user';
}

const getMockUser = (overrides?: Partial<User>): User => ({
id: '123',
name: 'John Doe',
email: 'john@example.com',
role: 'user',
...overrides,
});
```

Verwendung von "testing-patterns". Show me a custom render function

Erwartetes Ergebnis:

```typescript
export const renderWithTheme = (ui: React.ReactElement) => {
return render(
<ThemeProvider>{ui}</ThemeProvider>
);
};
```

Verwendung von "testing-patterns". How should I structure my tests?

Erwartetes Ergebnis:

Use describe blocks to group related tests: describe('ComponentName', () => { describe('Rendering', () => {...}); describe('User interactions', () => {...}); describe('Edge cases', () => {...}); });

Sicherheitsaudit

Sicher
v1 • 2/25/2026

Security review completed. All 42 static findings are false positives triggered by the static analyzer misinterpreting: (1) markdown code formatting backticks as shell commands, (2) TypeScript generics like Partial<X> as cryptographic patterns, and (3) the word 'APIs' as network reconnaissance. The skill is legitimate Jest testing documentation with no security concerns.

1
Gescannte Dateien
265
Analysierte Zeilen
0
befunde
1
Gesamtzahl Audits
Keine Sicherheitsprobleme gefunden
Auditiert von: claude

Qualitätsbewertung

38
Architektur
100
Wartbarkeit
87
Inhalt
50
Community
100
Sicherheit
100
Spezifikationskonformität

Was du bauen kannst

Setting up test infrastructure

Create custom render functions and factory utilities that wrap components with required providers like ThemeProvider, reducing boilerplate in every test.

Writing maintainable unit tests

Use factory functions to generate consistent test data, making tests easier to read, maintain, and update when data structures change.

Following TDD methodology

Apply the red-green-refactor cycle by writing failing tests first, then implementing minimal code to pass, ensuring tests drive development.

Probiere diese Prompts

Basic test setup
Help me set up a basic test file for a React component. Show me how to create a custom render function that wraps the component with a ThemeProvider.
Factory function for data
Create a factory function called getMockUser that returns a user object with default values for id, name, email, and role. Show how to override specific properties using Partial type.
Mocking a module
Show me how to mock a module like 'utils/analytics' in Jest. Include how to access the mock in the test and how to mock return values.
TDD workflow
Walk me through the TDD workflow for adding a new feature. Start with writing a failing test, then show the minimal implementation to pass it.

Bewährte Verfahren

  • Always use factory functions for props and data to keep tests DRY and consistent
  • Test behavior through the public API rather than implementation details
  • Use descriptive test names that explain what behavior is being tested

Vermeiden

  • Avoid testing mock behavior instead of actual component behavior
  • Do not duplicate test data across tests - use factory functions instead
  • Avoid testing implementation details that may change refactoring

Häufig gestellte Fragen

What is the factory pattern in testing?
The factory pattern uses functions like getMockUser() that return test data with sensible defaults. You can override specific properties as needed, keeping tests DRY and maintainable.
How do I create a custom render function?
Create a function that wraps the standard render with required providers. For example, renderWithTheme wraps your component with ThemeProvider so you do not repeat this in every test.
What is the TDD workflow?
TDD stands for Test-Driven Development. Follow three steps: Red (write a failing test), Green (write minimal code to pass), and Refactor (improve code while keeping tests passing).
How do I mock a module in Jest?
Use jest.mock('module-path') before your tests. You can provide a factory function to specify what the module should return. Access mocks using jest.requireMock().
What should I test: implementation or behavior?
Test behavior through the public API. Avoid testing internal state or implementation details because these may change during refactoring while the external behavior stays the same.
How do I organize large test suites?
Use describe blocks to group tests by category: Rendering, User interactions, and Edge cases. This makes tests easier to read and maintain.

Entwicklerdetails

Dateistruktur

📄 SKILL.md