mocking-strategies

Mock external dependencies in React Native unit tests with Jest.

3|Updated Dec 30, 2025
One-click install
npx skills add https://github.com/guicheffer/devorch-cli --skill mocking-strategies-guicheffer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mocking-strategies
Source: https://github.com/guicheffer/devorch-cli/tree/main/templates/skills/testing/mocking-strategies
Command: npx skills add https://github.com/guicheffer/devorch-cli --skill mocking-strategies-guicheffer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill simplifies and standardizes the process of mocking external dependencies in React Native unit tests, ensuring faster, more reliable, and isolated test execution.

Core Features & Use Cases

  • Comprehensive Mocking: Covers popular libraries like TanStack Query, Apollo GraphQL, React Navigation, and Zustand stores.
  • Native Module Mocking: Provides strategies for mocking native modules and core React Native APIs like Platform and useWindowDimensions.
  • Use Case: When testing a component that fetches data using useQuery from TanStack Query, you can use this Skill to mock the useQuery hook, providing predefined data or error states to test your component's UI and logic without making actual network requests.

Quick Start

Use the mocking-strategies skill to mock the useQuery hook from @tanstack/react-query with specific return values for your test.

Frequently Asked Questions about mocking-strategies

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I mock external dependencies in React Native unit tests using Jest?

You mock external dependencies in React Native unit tests by replacing real implementations with controlled test doubles using Jest. This ensures isolated, deterministic test execution by providing predefined data or error states for libraries like TanStack Query, Apollo GraphQL, and Zustand.

What is the best way to mock TanStack Query and Apollo GraphQL in Jest tests?

The best way to mock TanStack Query and Apollo GraphQL in Jest tests is to replace their data-fetching hooks, like useQuery, with controlled test doubles. This provides predefined data or error states to test component UI and logic without making actual network requests.

Can I mock core React Native APIs and native modules in Jest?

Yes, you can mock core React Native APIs and native modules in Jest. This Skill provides specific strategies to replace core APIs like Platform and useWindowDimensions with controlled test doubles for isolated and deterministic testing environments.

How do I mock React Navigation and Zustand stores for unit testing?

You mock React Navigation and Zustand stores by replacing their real implementations with controlled test doubles in Jest. This isolates component behavior during unit testing by providing predefined navigation states or store values without relying on actual library logic.

Why do my React Native unit tests fail when using external libraries?

React Native unit tests often fail when external libraries make network requests or access native modules. Mocking these dependencies with Jest replaces real implementations with deterministic test doubles, isolating component logic from unpredictable external factors.

Do I need to mock dependencies for isolated and deterministic React Native testing?

Yes, you need to mock dependencies for isolated and deterministic React Native testing. Replacing real implementations of libraries like TanStack Query or Zustand with controlled test doubles ensures faster, more reliable test execution without external side effects.