Generates Jest or Pytest tests following Ben's testing standards. Use when creating tests, adding test coverage, writing unit tests, mocking dependencies, or when user mentions testing, test cases, Jest, Pytest, fixtures, assertions, or coverage.
Generates Jest or Pytest tests following Ben's standards. Automatically triggers when you create tests, add coverage, or mention testing/Jest/Pytest.
/plugin marketplace add benshapyro/cadre-devkit-claude/plugin install benshapyro-cadre-devkit-claude@benshapyro/cadre-devkit-claudeThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Generate high-quality tests using Jest (JavaScript/TypeScript) or Pytest (Python) following established best practices.
__tests__/ or tests/ directoriesJavaScript/TypeScript:
src/
utils/
validator.ts
__tests__/
utils/
validator.test.ts
Python:
src/
utils/
validator.py
tests/
utils/
test_validator.py
Follow the Arrange-Act-Assert pattern:
// Jest example
describe('functionName', () => {
it('should handle valid input correctly', () => {
// Arrange
const input = 'valid';
// Act
const result = functionName(input);
// Assert
expect(result).toBe(expected);
});
it('should throw error for invalid input', () => {
// Negative test case
expect(() => functionName(null)).toThrow();
});
});
# Pytest example
class TestFunctionName:
def test_valid_input(self):
# Arrange
input_val = 'valid'
# Act
result = function_name(input_val)
# Assert
assert result == expected
def test_invalid_input_raises_error(self):
# Negative test case
with pytest.raises(ValueError):
function_name(None)
test_<what>_<condition>_<expected_result>test_user_login_with_valid_credentials_returns_tokentest_api_call_with_invalid_auth_raises_401jest.mock('../api/client');
it('should handle API errors gracefully', async () => {
apiClient.get.mockRejectedValue(new Error('Network error'));
await expect(fetchData()).rejects.toThrow('Network error');
});
@pytest.fixture
def sample_user():
return User(name='Test User', email='test@example.com')
def test_user_creation(sample_user):
assert sample_user.name == 'Test User'
@pytest.mark.parametrize("input,expected", [
("hello", "HELLO"),
("world", "WORLD"),
("", ""),
])
def test_uppercase(input, expected):
assert uppercase(input) == expected
describe('async operations', () => {
it('should fetch user data', async () => {
const user = await fetchUser(1);
expect(user.name).toBe('John');
});
it('should handle async errors', async () => {
await expect(fetchUser(-1)).rejects.toThrow('Invalid ID');
});
it('should resolve multiple promises', async () => {
const [users, posts] = await Promise.all([
fetchUsers(),
fetchPosts(),
]);
expect(users).toHaveLength(10);
expect(posts).toHaveLength(5);
});
});
describe('timer operations', () => {
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
});
it('should debounce function calls', () => {
const callback = jest.fn();
const debounced = debounce(callback, 500);
debounced();
debounced();
debounced();
expect(callback).not.toHaveBeenCalled();
jest.advanceTimersByTime(500);
expect(callback).toHaveBeenCalledTimes(1);
});
it('should timeout long operations', async () => {
const slowOperation = () => new Promise(r => setTimeout(r, 10000));
await expect(
Promise.race([
slowOperation(),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 1000)
),
])
).rejects.toThrow('Timeout');
});
});
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
describe('async component behavior', () => {
it('should show loading then data', async () => {
render(<UserProfile userId={1} />);
// Initially shows loading
expect(screen.getByText('Loading...')).toBeInTheDocument();
// Wait for data to appear
await waitFor(() => {
expect(screen.getByText('John Doe')).toBeInTheDocument();
});
// Loading should be gone
expect(screen.queryByText('Loading...')).not.toBeInTheDocument();
});
it('should handle user interactions', async () => {
const user = userEvent.setup();
render(<SearchForm />);
await user.type(screen.getByRole('textbox'), 'search term');
await user.click(screen.getByRole('button', { name: 'Search' }));
await waitFor(() => {
expect(screen.getByText('Results:')).toBeInTheDocument();
}, { timeout: 3000 }); // Custom timeout
});
});
import pytest
import asyncio
@pytest.mark.asyncio
async def test_async_fetch():
result = await fetch_data()
assert result is not None
@pytest.mark.asyncio
async def test_concurrent_operations():
results = await asyncio.gather(
fetch_users(),
fetch_posts(),
)
assert len(results) == 2
@pytest.mark.asyncio
async def test_async_timeout():
with pytest.raises(asyncio.TimeoutError):
await asyncio.wait_for(slow_operation(), timeout=1.0)
# Async fixtures
@pytest.fixture
async def async_client():
client = await create_async_client()
yield client
await client.close()
Before committing:
# JavaScript/TypeScript
npm run test
# Python
pytest -q
When generating tests:
Always explain what each test validates and why it's important.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.