unit-test
When to use this skill
Use this skill when:
- User asks to create or write unit tests
- User mentions testing, test coverage, or Bun test
- User wants to test specific functions, modules, or components
- User asks to add test files or improve test coverage
- User mentions test frameworks, mocking, or assertions
What this skill does
This skill provides expertise in creating comprehensive, well-structured unit tests using Bun's built-in testing framework. It covers test file creation, Bun test features, best practices, and RestMan-specific testing guidelines.
Core capabilities
1. Test File Creation
- Create test files with proper naming conventions:
*.test.ts,*_test.ts,*.spec.ts,*_spec.ts - Use TypeScript with proper types from
bun:test - Follow the project's code style guidelines (single quotes, camelCase, etc.)
2. Bun Test Framework Features
Basic Testing
import { test, expect, describe } from 'bun:test';
describe('feature name', () => {
test('should do something', () => {
expect(result).toBe(expected);
});
});
Lifecycle Hooks
beforeAll- Setup before all testsbeforeEach- Setup before each testafterEach- Cleanup after each testafterAll- Cleanup after all tests
Mocking
import { test, expect, mock } from 'bun:test';
const mockFn = mock(() => 'mocked value');
// or
const mockFn = jest.fn(() => 'mocked value');
Snapshot Testing
test('snapshot', () => {
expect(data).toMatchSnapshot();
});
Concurrent Testing
test.concurrent('async test 1', async () => {
// runs in parallel
});
test.serial('sequential test', () => {
// runs sequentially even with --concurrent flag
});
3. Test Organization Best Practices
- Group related tests with
describeblocks - Use descriptive test names that explain behavior
- Follow AAA pattern: Arrange, Act, Assert
- Test edge cases and error conditions
- Use
beforeEach/afterEachfor test isolation - Mock external dependencies and side effects
4. RestMan-Specific Testing Guidelines
When testing RestMan code:
- Follow TypeScript strict mode requirements
- Handle
noUncheckedIndexedAccess: true(indexed access can be undefined) - Use async/await for asynchronous operations
- Mock file system operations (fs/promises)
- Mock terminal UI components when testing business logic
- Test error handling with
instanceof Errorchecks - Use proper types from the codebase
5. Running Tests
Available test commands:
bun test- Run all testsbun test <filter>- Run tests matching filterbun test --watch- Watch modebun test --coverage- Generate coverage reportbun test --timeout 20- Set timeout (default 5000ms)bun test --bail- Exit after first failurebun test --update-snapshots- Update snapshots
Workflow
When asked to create tests:
- Understand the code - Read and analyze the source file to test
- Identify test scenarios - Determine what needs to be tested:
- Happy path functionality
- Edge cases
- Error conditions
- Async behavior
- Side effects (mocking needed)
- Create test file - Use proper naming convention matching source file
- Write comprehensive tests - Cover identified scenarios
- Follow project conventions - Match RestMan code style
- Run tests - Execute with
bun testto verify they pass - Report results - Explain what was tested and any issues found
Key principles
- Test behavior, not implementation - Focus on what the code does, not how
- Keep tests simple and readable - Tests are documentation
- One assertion per test when possible - Makes failures clear
- Mock external dependencies - File I/O, network, terminal UI
- Test edge cases - null, undefined, empty arrays, errors
- Maintain test isolation - Tests should not depend on each other
- Use descriptive names - Test names should read like documentation
Example test structure
See test structure reference for detailed examples.
Remember
- Always ask clarifying questions if the testing scope is unclear
- Suggest additional test scenarios if you identify gaps
- Follow RestMan's code style guidelines strictly
- Use TypeScript types properly
- Mock side effects appropriately
- Run tests after creating them to ensure they pass
- Be proactive about testing edge cases and error conditions
More from gitarbor/gitarbor-tui
skills-creator
Create and manage Agent Skills following the agentskills.io specification. Use when users want to create, validate, or modify skills for AI agents.
39opentui-dev
Build and modify terminal user interfaces using OpenTUI with React or Core API. Use when implementing terminal UIs, TUIs, CLI applications, interactive terminal components, keyboard navigation, terminal styling, or working on OpenTUI-based applications.
4opencode-agents
Create and configure custom OpenCode agents (primary and subagents) with specialized prompts, tools, permissions, and models. Use when the user wants to create, modify, or configure OpenCode agents, or mentions agent modes, tool permissions, or task delegation.
4theme-manager
Update and maintain GitArbor TUI themes, add new themes, modify existing themes, and ensure theme consistency. Use when working with colors, themes, src/theme.ts, or when user mentions theming, color schemes, or visual customization.
4nuxt-website
Build and maintain Vue 3/Nuxt 4 marketing websites. Use when working with website pages, components, layouts, SEO, Nuxt configuration, or when user mentions 'website', 'marketing site', 'landing page', 'docs site', Vue, or Nuxt.
4