Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

testing-patterns

/testing-patterns

Opisuje konwencje i wzorce testowania w monorepo Leather: konfigurację Vitest, nazewnictwo, fixtures i workflow TDD.

Repozytorium
mono ↗
Licencja
MIT
Ostatnia zmiana repozytorium
23.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 23.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Opisuje konwencje i wzorce testowania w monorepo Leather: konfigurację Vitest, nazewnictwo, fixtures i workflow TDD.

Oryginalny opis (EN)

Testing conventions and patterns for the Leather monorepo. Use when writing tests, creating test fixtures, or following TDD workflow. Covers Vitest setup, naming conventions, and common patterns.

Jak działa

  1. File Naming
  2. Test Structure
  3. Key Conventions
  4. Fixtures and Test Data
  5. BigNumber Assertions
  6. Running Tests
  7. Mocking
  8. React Component Tests
  9. Common Patterns
Sekcje z nagłówków SKILL.md, w oryginale · 136 linii, 370 słów
Podgląd SKILL.md
---
name: testing-patterns
description: Testing conventions and patterns for the Leather monorepo. Use when writing tests, creating test fixtures, or following TDD workflow. Covers Vitest setup, naming conventions, and common patterns.
---

# Leather Testing Patterns

The monorepo uses **Vitest** for testing. Tests are co-located with source files.

## File Naming

- Test files: `{module-name}.spec.ts` or `{module-name}.spec.tsx`
- Co-located with source: `src/utils/format.ts` → `src/utils/format.spec.ts`

## Test Structure

```typescript
import { functionUnderTest } from './module-name';

describe(functionUnderTest.name, () => {
  test('describes expected behavior', () => {
    // Arrange
    const input = createTestData();
    
    // Act
    const result = functionUnderTest(input);
    
    // Assert
    expect(result).toEqual(expected);
  });

  test('handles error case', () => {
    expect(() => functionUnderTest(invalidInput)).toThrowError();
  });
});
```

## Key Conventions

1. **Prefer `test` over `it`** — Both work, `test` is preferred for new code
2. **Prefer function reference for describe blocks**: `describe(functionName.name, () => {})` when testing a single exported function
3. **Descriptive test names**: Describe behavior, not implementation
4. **Test both success and error paths**

## Fixtures and Test Data

Define reusable test data at file scope:

```typescript
import BigNumber from 'bignumber.js';
import { createMoney } from './create-money';

const tenStx = createMoney(10, 'STX', 6);
const tenBtc = createMoney(10, 'BTC', 8);
const moneyArray = [tenStx, eightStx, nineStx];
```

## BigNumber Assertions

For Money and BigNumber comparisons:

```typescript
expect(result.amount.toString()).toEqual('100');
// NOT: expect(result.amount).toEqual(new BigNumber(100));
```

## Running Tests

```bash
# Run all tests
pnpm test

# Run tests for specific package
pnpm --filter @leather.io/utils test

# Run tests in watch mode
pnpm --filter @leather.io/bitcoin test -- --watch

# Run specific test file
pnpm --filter @leather.io/utils test -- src/money/create-money.spec.ts
```

## Mocking

For pure utility functions, avoid mocking internal modules. Mock only:
- External API calls
- Browser/native APIs
- Time-dependent functions

```typescript
import { vi } from 'vitest';

vi.useFakeTimers();
vi.setSystemTime(new Date('2025-01-15'));
```

## React Component Tests

For UI components in `@leather.io/ui`:

```typescript
import { render, screen } from '@testing-library/react';
import { Button } from './button';

describe('Button', () => {
  test('renders children', () => {
    render(<Button>Click me</Button>);
    expect(screen.getByText('Click me')).toBeInTheDocument();
  });
});
```

## Common Patterns

### Testing thrown errors
```typescript
test('throws on invalid input', () => {
  expect(() => functionUnderTest(null)).toThrowError('Expected error message');
});
```

### Testing async functions
```typescript
test('resolves with data', async () => {
  const result = await asyncFunction();
  expect(result).toEqual(expected);
});
```

### Testing type guards
```typescript
test('returns true for valid input', () => {
  expect(isValidType(validInput)).toBe(true);
});

test('returns false for invalid input', () => {
  expect(isValidType(invalidInput)).toBe(false);
});
```

Wersje

RepozytoriumWynikLicencja
Ta strona · leather-io/mono100MIT
Reprograme/redevkit100MIT
piomin/claude-ai-spring-boot100Apache-2.0
FrancoStino/opencode-skills-collection100MIT
rootcastleco/rei-skills100MIT
davila7/claude-code-templates100MIT
svngoku/coding-agents-skills100MIT
organvm-iv-taxis/a-i--skills100Apache-2.0
seandkendall/kiro-config100Apache-2.0

Migawka bazy z 13.11.2026 · wersja paczki af59ca9ab6ec (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100javascript-testing-patterns
    Wdraża strategie testowania w Jest, Vitest i Testing Library: testy jednostkowe, integracyjne i end-to-end z mockami, fixtures i TDD.
  • 95javascript-testing-patterns
    Wdraża strategie testowania w Jest, Vitest i Testing Library: testy jednostkowe, integracyjne i end-to-end z mockami, fixtures oraz TDD i BDD.
  • 91javascript-testing-patterns
    Wdraża strategie testowania w Jest, Vitest i Testing Library: testy jednostkowe, integracyjne i end-to-end, mocki, fixtures oraz podejście TDD i BDD.
  • 100vitest-testing-patterns
    Opisuje wzorce testowania w Vitest: testy jednostkowe, mocki, spye i testy w trybie przeglądarkowym.
  • 91javascript-testing-patterns
    Buduje strategie testów w JavaScript i TypeScript przez Jest, Vitest i Testing Library, z mockowaniem, fixture i TDD.
  • 100vitest
    Opisuje wzorce Vitest: konfiguracja testów, testy asynchroniczne, mocking przez vi.*, snapshoty i wydajność testów, bez metodyki TDD i MSW.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.