clean-tests
Skill193 starsChanged 7 months agoMITView on GitHub
Use when writing, fixing, editing, or refactoring TypeScript tests. Enforces Clean Code principles—fast tests, boundary coverage, one assert per test.
2 other projects use a version of this, 2 of them edited.
Adopted by
Most recently taken up by
- phanijapps/memexedited, first seen Oct 17, 2026
- ramybarsoum/claude-skillsedited, first seen Oct 13, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 2
- phanijapps/memex★ 046% same
- ramybarsoum/claude-skills★ 045% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository13 other files it gives its agents.
- boy-scoutSkill
- clean-commentsSkill
- clean-functionsSkill
- clean-generalSkill
- clean-namesSkill
- clean-testsSkill
- python-clean-codeSkill
- boy-scoutSkill
- clean-commentsSkill
- clean-functionsSkill
- clean-generalSkill
- clean-namesSkill
- typescript-clean-codeSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Test everything that could possibly break.
- Very specific: line 59
Don't use test.skip to hide problems.
- Distinctive: line 99
When you find a bug, write tests for all similar cases.
- Distinctive: line 115
When tests fail, look for patterns.
- Distinctive: line 124
Look at which code paths are untested.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Clean Tests
T1: Insufficient Tests
Test everything that could possibly break. Use coverage tools as a guide, not a goal.
// Bad - only tests happy path
test("divide", () => {
expect(divide(10, 2)).toBe(5);
});
// Good - tests edge cases too
test("divide normal", () => {
expect(divide(10, 2)).toBe(5);
});
test("divide by zero", () => {
expect(() => divide(10, 0)).toThrow(RangeError);
});
test("divide negative", () => {
expect(divide(-10, 2)).toBe(-5);
});T2: Use a Coverage Tool
Coverage tools report gaps in your testing strategy. Don't ignore them.
# Run with coverage
vitest run --coverage
# Aim for meaningful coverage, not 100%T3: Don't Skip Trivial Tests
Trivial tests document behavior and catch regressions. They're worth more than their cost.
// Worth having - documents expected behavior
test("user default role", () => {
const user = new User("Alice");
expect(user.role).toBe("member");
});T4: An Ignored Test Is a Question About an Ambiguity
Don't use test.skip to hide problems. Either fix the test or delete it.
// Bad - hiding a problem
test.skip("async operation", () => {
// flaky, fix later
});
// Good - either fix it or document why it's skipped
test.skip("cache invalidation - requires Redis (see CONTRIBUTING.md)", () => {
});T5: Test Boundary Conditions
Bugs congregate at boundaries. Test them explicitly.
test("pagination boundaries", () => {
const items = Array.from({ length: 100 }, (_, i) => i);
// First page
expect(paginate(items, 1, 10)).toEqual(items.slice(0, 10));
// Last page
expect(paginate(items, 10, 10)).toEqual(items.slice(90, 100));
// Beyond last page
expect(paginate(items, 11, 10)).toEqual([]);
// Page zero (invalid)
expect(() => paginate(items, 0, 10)).toThrow(RangeError);
// Empty list
expect(paginate([], 1, 10)).toEqual([]);
});T6: Exhaustively Test Near Bugs
When you find a bug, write tests for all similar cases. Bugs cluster.
// Found bug: off-by-one in date calculation
// Now test ALL date boundaries
test("month boundaries", () => {
expect(lastDayOfMonth(2024, 1)).toBe(31); // January
expect(lastDayOfMonth(2024, 2)).toBe(29); // Leap year February
expect(lastDayOfMonth(2023, 2)).toBe(28); // Non-leap February
expect(lastDayOfMonth(2024, 4)).toBe(30); // 30-day month
expect(lastDayOfMonth(2024, 12)).toBe(31); // December
});T7: Patterns of Failure Are Revealing
When tests fail, look for patterns. They often point to deeper issues.
// If all async tests fail intermittently,
// the problem isn't the tests—it's the async handlingT8: Test Coverage Patterns Can Be Revealing
Look at which code paths are untested. Often they reveal design problems.
// If you can't easily test a function, it probably does too much
// Refactor for testabilityT9: Tests Should Be Fast
Slow tests don't get run. Keep unit tests under 100ms each.
// Bad - hits real database
test("user creation", async () => {
const db = await connectToDatabase(); // Slow!
const user = await db.createUser("Alice");
expect(user.name).toBe("Alice");
});
// Good - uses mock or in-memory
test("user creation", async () => {
const db = new InMemoryDatabase();
const user = await db.createUser("Alice");
expect(user.name).toBe("Alice");
});Test Organization
F.I.R.S.T. Principles
- Fast: Tests should run quickly
- Independent: Tests shouldn't depend on each other
- Repeatable: Same result every time, any environment
- Self-Validating: Pass or fail, no manual inspection
- Timely: Written before or with the code, not after
One Concept Per Test
// Bad - testing multiple things
test("user", () => {
const user = new User("Alice", "alice@example.com");
expect(user.name).toBe("Alice");
expect(user.email).toBe("alice@example.com");
expect(user.isValid()).toBe(true);
user.activate();
expect(user.isActive).toBe(true);
});
// Good - one concept each
test("user stores name", () => {
const user = new User("Alice", "alice@example.com");
expect(user.name).toBe("Alice");
});
test("user stores email", () => {
const user = new User("Alice", "alice@example.com");
expect(user.email).toBe("alice@example.com");
});
test("new user is valid", () => {
const user = new User("Alice", "alice@example.com");
expect(user.isValid()).toBe(true);
});
test("user can be activated", () => {
const user = new User("Alice", "alice@example.com");
user.activate();
expect(user.isActive).toBe(true);
});Quick Reference
| Rule | Principle |
| T1 | Test everything that could break |
| T2 | Use coverage tools |
| T3 | Don't skip trivial tests |
| T4 | Ignored test = ambiguity question |
| T5 | Test boundary conditions |
| T6 | Exhaustively test near bugs |
| T7 | Look for patterns in failures |
| T8 | Check coverage when debugging |
| T9 | Tests must be fast (<100ms) |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

