typescript-testing-conventions

Enforces deterministic TypeScript test patterns using runtime assertions and type narrowing in Jest projects.

1|1|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/williamthorsen/codeassembly --skill typescript-testing-conventions-williamthorsen
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-testing-conventions
Source: https://github.com/williamthorsen/codeassembly/tree/main/packages/agents/content/skills/typescript-testing-conventions
Command: npx skills add https://github.com/williamthorsen/codeassembly --skill typescript-testing-conventions-williamthorsen

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Tests with conditional expect statements can silently pass without running any assertions, hiding real failures and reducing coverage. This Skill provides rules for writing deterministic TypeScript tests that always execute the same assertions and fail fast with clear messages. ## Core Features & Use Cases - Eliminate conditional expects: Replace if-guarded assertions with runtime assert() calls so tests never pass silently when preconditions fail. - Type narrowing in tests: Use assertion utilities like assert and assertIsNonNullable so TypeScript narrows types after checks, keeping tests type-safe. - Deterministic assertions: Ensure every test runs the same number of assertions and fails explicitly when arrays are empty or values are null. - Use Case: When writing a Jest test for a function returning an optional result, assert the result exists before checking its properties, so an unexpected undefined fails the test instead of skipping assertions. ## Quick Start Review my TypeScript test file and rewrite any conditional expect statements to use runtime assertions with proper type narrowing.

Frequently Asked Questions about typescript-testing-conventions

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

FAQPage Schema
How do I avoid conditional expect statements in Jest tests?

Replace if-guarded expects with a runtime assert() call before the assertions. If the precondition fails, the test fails immediately with a clear message instead of silently skipping all assertions and passing.

How to narrow TypeScript types inside test assertions?

Use assertion utilities like assert or assertIsNonNullable that act as TypeScript assertion functions. After the call, the compiler treats the value as non-null, so you can access properties without optional chaining or type errors.

Why do conditional expects cause tests to pass incorrectly?

When the condition is false, no assertions execute and the test still passes, creating silent failures. This hides bugs, reduces coverage, and makes it hard to tell whether the condition failing was expected behavior.

Can I use these testing patterns with frameworks other than Jest?

The patterns are framework-agnostic since they rely on runtime assertion functions rather than Jest-specific APIs. Any test runner that executes TypeScript can use assert-based guards to enforce deterministic assertions.

When should a test fail explicitly instead of skipping assertions?

Fail explicitly whenever a precondition is required for the test's intent, such as a non-empty array or a non-null result. Skipping assertions in these cases produces false positives and makes debugging harder.