P
đź’»DeveloppementIntermediateAll AIs

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

Isolate tests from external dependencies

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • 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.

Go further

Similar Prompts

đź’»DeveloppementIntermediateAll AIs

Namespace and Quota Management

Manage a multi-tenant cluster

0109
đź’»DeveloppementAdvancedAll AIs

Build a virtualized list

Handle massive data lists

0142
đź’»DeveloppementIntermediateAll AIs

REST API for ML Model

Exposing a model via an API

096
đź’»DeveloppementAdvancedAll AIs

Build a webhook system

Build webhook infrastructure

081