No slash command · from react-native-plugin
Configures Jest with jest-expo/react-native preset, React Testing Library Native, native module mocking, hook testing, and optional Detox/Maestro e2e setup for React Native projects.
Ships in react-native-plugin. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
| Layer | Framework |
|---|---|
| Component, hook, plain TS unit | Jest with jest-expo (Expo) or react-native preset (bare) |
| End-to-end (optional) | Detox (native automation) or Maestro (declarative YAML) |
Vitest is uncommon in RN — Jest's native module mocking and Metro integration is more battle-tested. If a project specifically uses Vitest in RN, follow it; otherwise default to Jest.
// jest.config.js
module.exports = {
preset: 'jest-expo',
setupFilesAfterEach: ['<rootDir>/jest.setup.ts'],
transformIgnorePatterns: [
'node_modules/(?!((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)/)',
],
};
Install: pnpm add -D jest jest-expo @testing-library/react-native @testing-library/jest-native.
// jest.config.js
module.exports = {
preset: 'react-native',
setupFilesAfterEach: ['<rootDir>/jest.setup.ts'],
transformIgnorePatterns: [
'node_modules/(?!((jest-)?react-native|@react-native(-community)?|@react-navigation/.*|react-native-mmkv|react-native-reanimated)/)',
],
};
Install: pnpm add -D jest @react-native/babel-preset @testing-library/react-native @testing-library/jest-native.
jest.setup.tsimport '@testing-library/jest-native/extend-expect';
// Common mocks for native modules
jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock'));
jest.mock('@react-native-async-storage/async-storage', () =>
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
);
// Silence common warnings
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
// src/components/UserCard.test.tsx
import { describe, it, expect, jest } from '@jest/globals';
import { render, screen, fireEvent } from '@testing-library/react-native';
import { UserCard } from './UserCard';
describe('UserCard', () => {
it('renders user name and email', () => {
render(<UserCard user={{ id: '1', name: 'Alice', email: '[email protected]' }} />);
expect(screen.getByText('Alice')).toBeOnTheScreen();
expect(screen.getByText('[email protected]')).toBeOnTheScreen();
});
it('calls onPress when card pressed', () => {
const onPress = jest.fn();
render(<UserCard user={{ id: '1', name: 'Alice', email: '[email protected]' }} onPress={onPress} />);
fireEvent.press(screen.getByLabelText('User card for Alice'));
expect(onPress).toHaveBeenCalledWith('1');
});
});
getByLabelText — accessibility labels (most stable on RN).getByRole(role, { name }) — works for Pressable, TextInput, etc.; weaker than web due to less consistent role mapping.getByText — for <Text> content.getByPlaceholderText — TextInput placeholders.getByDisplayValue — TextInput current value.getByTestId — last resort (use testID prop on RN components).fireEvent.press is the RN equivalent of userEvent.click. For text input:
fireEvent.changeText(screen.getByLabelText('Email'), '[email protected]');
For scroll, swipe, gesture interactions: more complex setup, often easier in e2e.
// react-native-mmkv
jest.mock('react-native-mmkv', () => ({
MMKV: jest.fn().mockImplementation(() => ({
set: jest.fn(),
getString: jest.fn(),
delete: jest.fn(),
contains: jest.fn(),
})),
}));
// expo-secure-store
jest.mock('expo-secure-store', () => ({
getItemAsync: jest.fn().mockResolvedValue(null),
setItemAsync: jest.fn().mockResolvedValue(undefined),
deleteItemAsync: jest.fn().mockResolvedValue(undefined),
}));
// react-native-keychain
jest.mock('react-native-keychain', () => ({
setGenericPassword: jest.fn().mockResolvedValue(undefined),
getGenericPassword: jest.fn().mockResolvedValue(false),
resetGenericPassword: jest.fn().mockResolvedValue(undefined),
}));
// expo-file-system
jest.mock('expo-file-system', () => ({
documentDirectory: '/test/',
readAsStringAsync: jest.fn(),
writeAsStringAsync: jest.fn(),
}));
jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock'));
The official mock disables animations and provides synchronous values — usually what tests want.
jest.mock('react-native-gesture-handler', () => {
const View = require('react-native').View;
return {
Swipeable: View,
DrawerLayout: View,
State: {},
ScrollView: View,
PanGestureHandler: View,
BaseButton: View,
Directions: {},
};
});
Or import from react-native-gesture-handler/jestSetup if shipped.
const mockNavigate = jest.fn();
jest.mock('@react-navigation/native', () => ({
useNavigation: () => ({ navigate: mockNavigate, goBack: jest.fn() }),
useRoute: () => ({ params: { userId: '123' } }),
}));
For Expo Router:
jest.mock('expo-router', () => ({
useRouter: () => ({ push: jest.fn(), replace: jest.fn(), back: jest.fn() }),
useLocalSearchParams: () => ({ id: '123' }),
}));
// src/hooks/useDebounce.test.ts
import { renderHook, act } from '@testing-library/react-native';
import { useDebounce } from './useDebounce';
describe('useDebounce', () => {
it('debounces value updates', () => {
jest.useFakeTimers();
const { result, rerender } = renderHook(({ value }) => useDebounce(value, 300), {
initialProps: { value: 'a' },
});
expect(result.current).toBe('a');
rerender({ value: 'b' });
expect(result.current).toBe('a');
act(() => { jest.advanceTimersByTime(300); });
expect(result.current).toBe('b');
jest.useRealTimers();
});
});
For RN < 0.71, use @testing-library/react-hooks instead.
msw works in RN tests via the jsdom polyfill in jest-expo:
// jest.setup.ts
import { setupServer } from 'msw/node';
import { http, HttpResponse } from 'msw';
const server = setupServer(
http.get('https://api.example.com/users', () =>
HttpResponse.json([{ id: '1', name: 'Alice' }])
)
);
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
export { server };
Per-test override:
import { http, HttpResponse } from 'msw';
server.use(http.get('https://api.example.com/users', () => HttpResponse.error()));
import { render } from '@testing-library/react-native';
import { UserCard } from './UserCard';
it('matches snapshot', () => {
const { toJSON } = render(<UserCard user={{ id: '1', name: 'Alice', email: '[email protected]' }} />);
expect(toJSON()).toMatchSnapshot();
});
RN snapshot trees are LARGE — 500+ lines per component is normal. Review noise outweighs value for most components. Use only for stable design-system primitives.
Prefer toMatchInlineSnapshot() for small expected outputs — keeps them in test file for easy review.
Target ≥80% on:
lib/).Skip / lower bar:
navigation/*).App.tsx / root layout.// jest.config.js
module.exports = {
preset: 'jest-expo',
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/navigation/**',
'!src/**/*.types.ts',
'!src/App.tsx',
'!**/node_modules/**',
],
};
Native automation framework. Drives real iOS Simulator / Android Emulator. Higher fidelity, higher setup cost.
// package.json
"devDependencies": { "detox": "^20.x" }
"detox": { "configurations": {...} }
If detox not in deps, skip this section.
pnpm add -D detox @config-plugins/detox..detoxrc.js with iOS Simulator / Android Emulator targets.detox build --configuration ios.sim.debug.detox test --configuration ios.sim.debug.Requires:
import { device, element, by, expect } from 'detox';
describe('Login flow', () => {
beforeAll(async () => {
await device.launchApp({ newInstance: true });
});
it('user can log in and reach dashboard', async () => {
await element(by.id('login-email')).typeText('[email protected]');
await element(by.id('login-password')).typeText('longenough');
await element(by.id('login-submit')).tap();
await expect(element(by.id('dashboard-title'))).toBeVisible();
});
});
Async assertions are first-class: toBeVisible, toExist, toHaveText, toHaveLabel.
testID props on RN components map to Detox's by.id(). Use accessibility labels for by.label().
For most projects, Detox is overkill. Use it when:
Declarative YAML-based e2e. Simpler than Detox, less flexible.
If maestro CLI is installed (no npm package required) and .maestro/ folder exists with YAML flows.
# .maestro/login.yaml
appId: com.example.myapp
---
- launchApp
- tapOn:
id: "login-email"
- inputText: "[email protected]"
- tapOn:
id: "login-password"
- inputText: "longenough"
- tapOn:
id: "login-submit"
- assertVisible:
id: "dashboard-title"
Run: maestro test .maestro/login.yaml.
| Aspect | Maestro | Detox |
|---|---|---|
| Test format | YAML | JavaScript/TypeScript |
| Setup complexity | Low (CLI install) | High (native build config) |
| Flexibility | Limited (declarative) | High (full programmability) |
| Speed | Fast | Slow |
| Custom logic | Limited (JS expressions) | Full Node access |
| CI integration | Easy | Mac runners required for iOS |
Use Maestro for smoke flows; use Detox when you need programmability.
The qa-engineer agent has a hard 3-attempt cap on fixing failing tests. Mark genuinely flaky tests it.skip(...) with a comment after attempt #3 — RN tests are particularly prone to flakiness from native module mocks.
transformIgnorePatterns — RN packages ship ES modules, Jest barfs without transform.getByTestId everywhere instead of accessible queries.jest.useFakeTimers() for animation/debounce tests — real timers slow tests by 100x.beforeEach(() => jest.clearAllMocks()) — state leaks between tests.What SKILL.md sets; muted values are Claude Code's defaults
5 skills in this plugin
/rn-conventionsReact Native project structure, Expo vs bare workflow detection, app.json/app.config.js patterns, asset handling, fonts, styling approaches, hot-reload-friendly idioms.
Use this skill to:
- Detect Expo (managed/dev-client/EAS/ejected) vs bare RN workflow.
- Pick correct project layout for each workflow.
- Configure app.json / app.config.js with bundle ID, splash, icons, deep link schemes.
- Handle assets, fonts, images correctly.
- Pick a styling approach (StyleSheet / NativeWind / restyle / styled-components).
Do NOT use this skill for:
- Platform-specific branching (see rn-platform-specific).
- Navigation (see rn-navigation).
- Storage (see rn-state-and-storage).
- Testing (see rn-testing).
/rn-navigationNavigation in React Native — both React Navigation v7 (classical, modular) and Expo Router (file-based, Expo 49+). Stack, tab, drawer navigators, deep linking, typed navigation, modal presentation, authentication flow patterns.
Use this skill to:
- Pick navigation lib based on what's installed (@react-navigation/* vs expo-router).
- Configure typed routes with ParamList types or Expo Router's generated types.
- Set up deep linking (URL schemes, Universal Links, App Links).
- Build authentication flow with conditional navigators.
- Use modal presentation correctly.
Do NOT use this skill for:
- Project structure (see rn-conventions).
- Platform-specific differences (see rn-platform-specific).
- State / storage (see rn-state-and-storage).
- Testing navigation (see rn-testing).
/rn-platform-specificiOS / Android platform-specific code in React Native: Platform.OS, Platform.select, .ios.tsx / .android.tsx file extensions, native modules, permissions, safe area handling, status bar.
Use this skill to:
- Branch code at runtime via Platform.OS / Platform.select.
- Use file extensions for whole-component swaps.
- Link and use native modules (Expo SDK or autolinked bare).
- Handle permissions across platforms.
- Configure status bar and safe area correctly.
Do NOT use this skill for:
- General project structure (see rn-conventions).
- Navigation (see rn-navigation).
- Storage (see rn-state-and-storage).
- Testing (see rn-testing).
/rn-state-and-storageState management and storage choice in React Native. State libs work mostly the same as web (Zustand, Jotai, Redux Toolkit, TanStack Query, Context); storage choice is RN-specific — AsyncStorage, MMKV, SecureStore, Keychain. Hydration patterns, splash screen handling, secrets discipline.
Use this skill to:
- Pick state management lib (matches web React intuition).
- Pick storage by sensitivity (AsyncStorage / MMKV / SecureStore / Keychain).
- Hydrate state on app start without UI flicker.
- Persist Zustand store across app restarts.
- Avoid storing secrets in plaintext storage.
Do NOT use this skill for:
- General project conventions (see rn-conventions).
- Platform-specific code (see rn-platform-specific).
- Navigation (see rn-navigation).
- Testing state/storage (see rn-testing).
npx claudepluginhub aratkruglik/claude-sdlc --plugin react-native-pluginOther plugins' skills for the same job