unit-test

When to use this skill

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "unit-test" with this command: npx skills add gitarbor/gitarbor-tui/gitarbor-gitarbor-tui-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.)

  1. 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 tests

  • beforeEach

  • Setup before each test

  • afterEach

  • Cleanup after each test

  • afterAll

  • 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 });

  1. Test Organization Best Practices
  • Group related tests with describe blocks

  • Use descriptive test names that explain behavior

  • Follow AAA pattern: Arrange, Act, Assert

  • Test edge cases and error conditions

  • Use beforeEach /afterEach for test isolation

  • Mock external dependencies and side effects

  1. 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 Error checks

  • Use proper types from the codebase

  1. Running Tests

Available test commands:

  • bun test

  • Run all tests

  • bun test <filter>

  • Run tests matching filter

  • bun test --watch

  • Watch mode

  • bun test --coverage

  • Generate coverage report

  • bun test --timeout 20

  • Set timeout (default 5000ms)

  • bun test --bail

  • Exit after first failure

  • bun 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 test to 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

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

opentui-dev

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

Test Case Generator

Automatically generate complete unit test code including imports, test cases, mocks, and assertions for Jest, Mocha, or Pytest from given code.

Registry SourceRecently Updated
0633
Profile unavailable
Security

QA & Test Engineering Command Center

Comprehensive QA system for planning strategy, writing tests, analyzing coverage, automating pipelines, performance and security testing, defect triage, and...

Registry SourceRecently Updated
0516
Profile unavailable