effect-patterns-testing
БесплатноБез исполняемых скриптовНе проверенEffect-TS patterns for Testing. Use when working with testing in Effect-TS applications.
Об этом скилле
Effect-TS Patterns: Testing
This skill provides 10 curated Effect-TS patterns for testing. Use this skill when working on tasks related to:
- testing
- Best practices in Effect-TS applications
- Real-world patterns and solutions
🟢 Beginner Patterns
Your First Effect Test
Rule: Use Effect.runPromise in tests to run and assert on Effect results.
Good Example:
import { describe, it, expect } from "vitest"
import { Effect } from "effect"
// ============================================
// Code to test
// ============================================
const add = (a: number, b: number): Effect.Effect<number> =>
Effect.succeed(a + b)
const divide = (a: number, b: number): Effect.Effect<number, Error> =>
b === 0
? Effect.fail(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
const fetchUser = (id: string): Effect.Effect<{ id: string; name: string }> =>
Effect.succeed({ id, name: `User ${id}` })
// ============================================
// Tests
// ============================================
describe("Basic Effect Tests", () => {
it("should add two numbers", async () => {
const result = await Effect.runPromise(add(2, 3))
expect(result).toBe(5)
})
it("should divide numbers", async () => {
const result = await Effect.runPromise(divide(10, 2))
expect(result).toBe(5)
})
it("should fail on divide by zero", async () => {
await expect(Effect.runPromise(divide(10, 0))).rejects.toThrow(
"Cannot divide by zero"
)
})
it("should fetch a user", async () => {
const user = await Effect.runPromise(fetchUser("123"))
expect(user).toEqual({
id: "123",
name: "User 123",
})
})
})
// ============================================
// Testing Effect.gen programs
// ============================================
const calculateDiscount = (price: number, quantity: number) =>
Effect.gen(function* () {
if (price <= 0) {
return yield* Effect.fail(new Error("Invalid price"))
}
const subtotal = price * quantity
const discount = quantity >= 10 ? 0.1 : 0
const total = subtotal * (1 - discount)
return { subtotal, discount, total }
})
describe("Effect.gen Tests", () => {
it("should calculate without discount", async () => {
const result = await Effect.runPromise(calculateDiscount(10, 5))
expect(result.subtotal).toBe(50)
expect(result.discount).toBe(0)
expect(result.total).toBe(50)
})
it("should apply bulk discount", async () => {
const result = await Effect.runPromise(calculateDiscount(10, 10))
expect(result.subtotal).toBe(100)
expect(result.discount).toBe(0.1)
expect(result.total).toBe(90)
})
it("should fail for invalid price", async () => {
await expect(
Effect.runPromise(calculateDiscount(-5, 10))
).rejects.toThrow("Invalid price")
})
})
Rationale:
Test Effect programs by running them with Effect.runPromise and using standard test assertions on the results.
Testing Effect code is straightforward:
- Effects are values - Build them in tests like any other value
- Run to get results - Use
Effect.runPromiseto execute - Assert normally - Standard assertions work on the results
Test Effects with Services
Rule: Provide test implementations of services to make Effect programs testable.
Good Example:
import { describe, it, expect } from "vitest"
import { Effect, Context } from "effect"
// ============================================
// 1. Define a service
// ============================================
class UserRepository extends Context.Tag("UserRepository")<
UserRepository,
{
readonly findById: (id: string) => Effect.Effect<User | null>
readonly save: (user: User) => Effect.Effect<void>
}
>() {}
interface User {
id: string
name: string
email: string
}
// ============================================
// 2. Code that uses the service
// ============================================
const getUser = (id: string) =>
Effect.gen(function* () {
const repo = yield* UserRepository
const user = yield* repo.findById(id)
if (!user) {
return yield* Effect.fail(new Error(`User ${id} not found`))
}
return user
})
const createUser = (name: string, email: string) =>
Effect.gen(function* () {
const repo = yield* UserRepository
const user: User = {
id: crypto.randomUUID(),
name,
email,
}
yield* repo.save(user)
return user
})
// ============================================
// 3. Create a test implementation
// ============================================
const makeTestUserRepository = (initialUsers: User[] = []) => {
const users = new Map(initialUsers.map(u => [u.id, u]))
return UserRepository.of({
findById: (id) => Effect.succeed(users.get(id) ?? null),
save: (user) => Effect.sync(() => { users.set(user
Установить effect-patterns-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл effect-patterns-testing?
Effect-TS patterns for Testing. Use when working with testing in Effect-TS applications.
Как установить скилл effect-patterns-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл effect-patterns-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic