testing-unit
Purpose
This skill equips the AI to assist with unit testing using frameworks like Jest/Vitest for JavaScript, pytest for Python, Go's testify, RSpec for Ruby, XCTest for Swift, and JUnit5 for Java. It focuses on mocking dependencies, creating stubs, and ensuring test isolation to verify code behavior in controlled environments.
When to Use
Use this skill when writing new unit tests, debugging existing ones, or refactoring code that requires isolated testing. Apply it for TDD workflows, mocking external APIs or databases, or ensuring functions work independently. For example, use it when a function depends on a network call—mock it to test locally without real dependencies.
Key Capabilities
- Mocking: Create mocks for functions or modules, e.g., in Jest with
jest.mock('module')to replace real implementations. - Stubbing: Define stub responses, like in pytest using
monkeypatch.setattr()to fake object methods. - Isolation: Run tests in isolation, such as using Go's testify to assert without side effects, or JUnit5's
@TempDirfor isolated file operations. - Framework-Specific: Support for Jest/Vitest assertions (e.g.,
expect().toBe()), pytest fixtures for setup/teardown, RSpec'sdoublefor mocks, XCTest'ssetUp()for isolation, and JUnit5's@Mockannotations. - Config Formats: Use Jest's
jest.config.jswith{ testEnvironment: 'node', setupFilesAfterEnv: ['<rootDir>/setupTests.js'] }for custom mocks; pytest'spytest.iniwith[pytest] addopts = -vfor verbose output.
Usage Patterns
To accomplish unit testing tasks, follow these steps: 1) Identify dependencies to mock (e.g., HTTP calls). 2) Set up mocks or stubs in your test file. 3) Write assertions to verify outputs. 4) Run tests with appropriate flags. For TDD, write a failing test first, then implement code. In Jest, structure tests with describe() blocks; in pytest, use fixtures for shared setup. Always isolate tests by avoiding global state—use beforeEach() in Jest or @pytest.fixture(scope='function') in pytest.
More from alphaonedev/openclaw-graph
playwright-scraper
Playwright web scraping: dynamic content, auth flows, pagination, data extraction, screenshots
1.4Kgcp-iam
Manages identity and access control for Google Cloud resources using IAM policies and roles.
370humanize-ai-text
AI text humanization: reduce AI-detection patterns, natural phrasing, tone adjustment
262macos-automation
AppleScript, JXA, Shortcuts, Automator, osascript, System Events, accessibility API
173tavily-web-search
Tavily: web search optimized for AI agents, answer synthesis, domain filtering, depth control
155clawflows
OpenClaw workflow automation: multi-step task chains, conditional logic, triggers, schedule
102