unit-tests-ts

Generates TypeScript unit tests using Node.js native test runner and assertion libraries.

1|Updated Apr 25, 2025
One-click install
npx skills add https://github.com/Gabr1elaugus700/WorkaPool --skill unit-tests-ts-gabr1elaugus700
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-tests-ts
Source: https://github.com/Gabr1elaugus700/WorkaPool/tree/main/.github/skills/unit-tests-ts
Command: npx skills add https://github.com/Gabr1elaugus700/WorkaPool --skill unit-tests-ts-gabr1elaugus700

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing unit tests for TypeScript backends often leads to inconsistent tooling choices and heavy dependencies on external frameworks like Jest or Vitest. This Skill enforces a strict, dependency-free testing approach using only the Node.js built-in test runner, producing isolated and readable tests. ## Core Features & Use Cases - Native Test Generation: Creates complete test files using node:test and node:assert/strict with AAA (Arrange, Act, Assert) structure. - Strict Dependency Isolation: Mocks repositories and external services using the native mock.fn() and mock.method() APIs, never touching databases, filesystems, or external APIs. - Design Feedback: Detects hard-to-test code such as temporal coupling (new Date()) or static calls and suggests dependency injection improvements. - Use Case: Ask for unit tests for a TypeScript service class, and receive a scenario list, a mock isolation strategy, and a complete runnable test file with no external test dependencies. ## Quick Start Ask the assistant to create unit tests for your TypeScript service class using only the native Node.js test runner and assert module.

Frequently Asked Questions about unit-tests-ts

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

FAQPage Schema
How do I write unit tests in Node.js without Jest or Vitest?

Use the built-in node:test module by importing describe, it, and mock from 'node:test', and assertions from 'node:assert/strict'. This runs natively on Node.js 20+ with zero external test dependencies.

How to mock dependencies with the Node.js native test runner?

Use mock.method(object, 'methodName') to spy on or replace object methods, and mock.fn() to create standalone fake functions. Inject these mocks explicitly into the system under test or use Partial<T> fake objects.

Does node:test support TypeScript projects?

Yes, the native test runner works with TypeScript backends on Node.js 20+, typically via a TypeScript loader or pre-compilation. Tests import from 'node:test' and 'node:assert/strict' with full type safety.

How do I test async errors with node:assert?

Use assert.rejects() for promises that should throw and assert.throws() for synchronous errors. Validate specific error properties, not just the error type, to ensure domain errors behave as expected.

What are the limitations of the Node.js native test runner?

The native runner lacks some ecosystem features like snapshot testing and rich watch-mode UIs found in Jest or Vitest. Code with temporal coupling like new Date() or static calls is hard to test and should be refactored toward dependency injection first.