Testing guide

From vultisig/vultisig-windows · View interactive version

Testing guide is an AI agent skill from the GitHub repository vultisig/vultisig-windows. Comprehensive testing guide covering unit, integration, and E2E tests. Reference for deciding what to test and how, with Vitest and Playwright patterns.

How to use this skill

Skill file

Testing Guide — Unit, Integration & E2E

Test Pyramid & Decision Tree

What type of test should I write?

Is it a pure function (mapper, util, core logic)?
  → UNIT TEST (Vitest)

Is it a hook that composes queries/state?
  → INTEGRATION TEST (Vitest + renderHook)

Is it a component with user interaction?
  → COMPONENT TEST (Vitest + Testing Library)

Is it a critical user flow (place order, login, navigate)?
  → E2E TEST (Playwright)

Is it a styled component with no logic?
  → DON'T TEST IT

Smart test evaluation — when to skip

Skip tests for:


Unit Tests (Vitest)

What to unit test

Structure

import { describe, it, expect } from 'vitest'
import { mapOrderFromApi } from '../data/mappers/order'

describe('mapOrderFromApi', () => {
  it('maps filled order with correct status', () => {
    const apiResponse = createMockApiOrder({ status: 'FILLED' })
    const result = mapOrderFromApi(apiResponse)
    expect(result.status).toBe('filled')
    expect(result.fillPrice).toBeDefined()
  })

  it('handles zero-quantity edge case', () => {
    const apiResponse = createMockApiOrder({ qty: '0' })
    const result = mapOrderFromApi(apiResponse)
    expect(result.quantity).toBe(0)
  })
})

Patterns

File location


Integration Tests (Vitest + Testing Library)

What to integration test

Hook testing

import { renderHook, waitFor } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { useOrdersWithMarkets } from '../data/hooks'

const createWrapper = () => {
  const queryClient = new QueryClient({
    defaultOptions: { queries: { retry: false } },
  })
  return ({ children }: { children: ReactNode }) => (
    <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
  )
}

describe('useOrdersWithMarkets', () => {
  it('combines orders and markets data', async () => {
    // Mock API responses
    server.use(
      http.get('/api/orders', () => HttpResponse.json(mockOrders)),
      http.get('/api/markets', () => HttpResponse.json(mockMarkets)),
    )

    const { result } = renderHook(() => useOrdersWithMarkets(), {
      wrapper: createWrapper(),
    })

    await waitFor(() => expect(result.current.isSuccess).toBe(true))
    expect(result.current.data).toHaveLength(3)
    expect(result.current.data[0].market).toBeDefined()
  })
})

Component testing

import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'

describe('OrderForm', () => {
  it('validates minimum order size', async () => {
    render(<OrderForm />, { wrapper: TestProviders })

    const input = screen.getByLabelText('Amount')
    await userEvent.type(input, '0.001')
    await userEvent.click(screen.getByText('Place Order'))

    expect(screen.getByText(/minimum order size/i)).toBeInTheDocument()
  })
})

Patterns


E2E Tests (Playwright)

What to E2E test

Structure

import { test, expect } from '@playwright/test'

test.describe('Market Order', () => {
  test('places a market buy order', async ({ page }) => {
    await page.goto('/trading/BTC-USD')

    // Fill order form
    await page.getByLabel('Amount').fill('0.01')
    await page.getByRole('button', { name: 'Buy' }).click()

    // Verify confirmation
    await expect(page.getByText('Order placed')).toBeVisible()

    // Verify in order history
    await page.getByRole('tab', { name: 'History' }).click()
    await expect(page.getByText('Market Buy')).toBeVisible()
  })

  test('shows validation error for zero amount', async ({ page }) => {
    await page.goto('/trading/BTC-USD')
    await page.getByLabel('Amount').fill('0')
    await page.getByRole('button', { name: 'Buy' }).click()
    await expect(page.getByText(/minimum/i)).toBeVisible()
  })
})

File location

Patterns

```typescript

class TradingPage {

constructor(private page: Page) {}

async placeMarketOrder(side: 'buy' | 'sell', amount: string) { ... }

async getOrderHistory() { ... }

}

```

Running

yarn test:e2e              # Run all E2E tests
npx playwright test --ui   # Interactive mode
npx playwright test --debug # Debug mode

Test Data Factories

Create reusable factories for test data to avoid duplication:

// tests/factories/order.ts
export const createMockOrder = (overrides: Partial<Order> = {}): Order => ({
  id: 'order-1',
  side: 'buy',
  type: 'market',
  status: 'pending',
  amount: 1.0,
  price: 50000,
  createdAt: new Date().toISOString(),
  ...overrides,
})

What NOT to Test

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.