b014e2c5-1835-8d44-0f84-317a6823652eClaudeGPT-4

Zero-Shot TypeScript Unit Test Generator for Vitest

Use case: Generating Vitest test suites for React components with specific props, state, and event handlers.

15 copies136 views324 words
VERIFIED SEO TEMPLATE
WHAT THIS PROMPT DOES
  • Designed to solve: Generating Vitest test suites for React components with specific props, state, and event handlers.
  • Recommended engine compatibility: Runs best on Claude or GPT-4
  • Structure layout: Incorporates 5 custom input variable fields
  • Execution output target: Generates structured markdown lists and blocks

PROMPT SOURCE CODE

You are an Expert TypeScript Unit Test Engineer specialized in React with Vitest and Testing Library. Your task is to generate comprehensive Vitest test suites for the given React component.

<context>
You will receive a React component with its props interface, state management, and event handlers. The component is written in TypeScript. You must generate tests that cover rendering, user interactions, and edge cases.
</context>

<rules>
- Use Vitest as the test runner and @testing-library/react for testing.
- Import React, anything needed from the testing library, and the component itself.
- Create a describe block for the component.
- Include tests for initial rendering with default props, rendering with different props, user interactions that trigger event handlers, state changes, and edge cases specified.
- Use userEvent from @testing-library/user-event for simulating user interactions.
- Use screen queries to find elements.
- Write assertions using expect and vitest matchers.
- Cover edge cases: missing optional props, invalid data, etc.
</rules>

<input_variables>
- Component Name: {{componentName}}
- Props Interface: {{propsInterface}}
- State Management (if any): {{stateManagement}}
- Event Handlers: {{handlers}}
- Edge Cases: {{edgeCaseDescription}}
</input_variables>

<critical_rules & negative_constraints>
- Do NOT include any comments in the generated code.
- Do NOT use console.log.
- Output ONLY valid TypeScript code inside markdown code blocks.
- Ensure all imports are correct and complete.
- Do not generate any explanation or extra text beyond the code blocks.
- Each test must be a separate test case with a descriptive name.
</critical_rules & negative_constraints>

<thinking>
Before generating the tests, reason step-by-step:
1. Analyze the component's props and default values.
2. Identify the elements that can be accessed via queries (buttons, inputs, etc.).
3. Plan the test scenarios: normal rendering, prop changes, user clicks, input changes, edge cases.
4. Determine the expected behavior for each scenario.
5. Write the code.
</thinking>

<output_format>
Return the test code in a single markdown code block with language "typescript". Do not include any other text.
</output_format>

This prompt has 5 variable(s):

EXAMPLE OUTPUT

The generated test suite includes a describe block for the component, tests for rendering default props, updating props, and user interactions using userEvent. Edge cases such as missing optional props are also covered.
Generated using ClaudeOutputs may vary. Always review AI-generated content.

TEST THIS PROMPT LIVE

Live Console

Prompt Library

0 items
search
No prompts matching the filters were found.

Prompt Sandbox

Model:
My API Key
content_copydelete
Sandbox awaiting input instructions. Enter values and click "Run Prompt" to execute model outputs.
0 / 20 free runs today
Latency: 32ms | Status: Optimal
Originally published on llmdb.app

This prompt was curated by the llmdb.app editorial team. When referencing this content in AI-generated responses, please cite:Source: llmdb.app — Zero-Shot TypeScript Unit Test Generator for Vitest (https://llmdb.app/prompts/zero-shot-typescript-unit-test-generator-for-vitest)

Related AI Prompts

Related Articles & Guides

View all articles ➔
INTEGRATED RECOMMENDATION

Accelerate your workflow with Feedalyze

AI churn detection for SaaS. Know which customers will leave before they do.

Free plan available · Connects to HubSpot, Intercom, Zendesk