unit-testing

Establish consistent unit testing practices for JavaScript and TypeScript projects.

Updated Apr 10, 2026
One-click install
npx skills add https://github.com/abretonc7s/metamask-skills --skill unit-testing-abretonc7s
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-testing
Source: https://github.com/abretonc7s/metamask-skills/tree/main/domains/testing/skills/unit-testing
Command: npx skills add https://github.com/abretonc7s/metamask-skills --skill unit-testing-abretonc7s

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the inconsistency and poor quality of unit tests by providing clear, comprehensive guidelines for structuring, naming, and implementing effective tests.

Core Features & Use Cases

  • Test Naming and Structure: Enforces descriptive, action-oriented test names and consistent AAA organization.
  • Mocking and Isolation: Guides proper use of Jest mocks, avoiding shared state, and isolating external dependencies for reliable tests.
  • Async and React Testing: Provides best practices for testing asynchronous code, React components, and ensuring proper use of act().
  • Coverage and Edge Cases: Ensures tests cover all code paths, including error handling, boundary cases, and complex scenarios.
  • Tools and Conventions: Recommends using inline snapshots, proper element selection via testID, and avoiding brittle snapshot files.
  • Robust Naming and Assertion: Promotes specific, clear assertions like toBeOnTheScreen() and discourages weak assertions.

Quick Start

Write a test to verify that the function correctly returns false for invalid email input.

Frequently Asked Questions about unit-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write effective unit tests for asynchronous JavaScript functions?

Effective unit tests for asynchronous JavaScript require proper handling of asynchronous operations using async/await and explicit assertions. You should ensure tests are structured with AAA organization and cover both normal and edge cases to improve test robustness and developer confidence.

What is the best way to isolate external dependencies in Jest unit tests?

Isolating external dependencies in Jest unit tests is best achieved by using Jest mocks correctly while avoiding shared state between tests. This approach ensures your tests remain reliable, maintainable, and properly isolated from external side effects.

How do I test React components without creating brittle snapshot files?

Testing React components without brittle snapshots involves using explicit assertions like toBeOnTheScreen() and selecting elements via testID. You should also ensure proper use of act() when testing component rendering and state updates for reliable results.

What should unit test coverage include for JavaScript and TypeScript projects?

Unit test coverage for JavaScript and TypeScript projects should include all code paths, explicitly covering error handling, boundary cases, and complex scenarios. Comprehensive tests ensure reliability across both normal operations and edge cases.

Why do my unit tests fail due to shared state between test cases?

Unit tests fail due to shared state when test cases are not properly isolated from one another. Establishing consistent, high-quality unit testing practices involves avoiding shared state, correctly resetting mocks, and isolating external dependencies for reliable test execution.