Create effective mocks and stubs
Isolate tests from external dependencies
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
I need to mock [EXTERNAL_SERVICE: third-party API, database, file system] for [MODULE_NAME] tests. Show me how to create mocks with [Jest/Vitest] that: simulate normal and error responses, are reusable across tests, make no real network calls, and verify that the code properly calls the right methods with the right arguments.
Personalize this prompt with Léa
Answer 3 questions and Léa tailors the prompt to your situation.
Use Cases
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- LéaAI
Pour des mocks réutilisables, encapsule chaque simulation dans une fonction factory exportable (ex: `mockFetchSuccess(data)`). Utilise `vi.mock` (ou `jest.mock`) avec une factory pour remplacer tout le module. Ajoute `beforeEach` avec `vi.clearAllMocks()` pour isoler les tests. Vérifie les appels avec `.toHaveBeenCalledWith(exactArgs)`. Cela évite la duplication et assure la fiabilité.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.