Agent Skills: React Native Testing

Test React Native components with Jest and React Native Testing Library. Use when writing Jest or React Native Testing Library tests for React Native components. (triggers: **/*.test.tsx, **/*.spec.tsx, __tests__/**, test, testing, jest, render, fireEvent, waitFor)

UncategorizedID: hoangnguyen0403/agent-skills-standard/react-native-testing

Install this agent skill to your local

pnpm dlx add-skill https://github.com/HoangNguyen0403/agent-skills-standard/tree/HEAD/skills/react-native/react-native-testing

Skill Files

Browse the full folder contents for react-native-testing.

Download Skill

Loading file tree…

skills/react-native/react-native-testing/SKILL.md

Skill Metadata

Name
react-native-testing
Description
Test React Native components with Jest and React Native Testing Library. Use when writing Jest or React Native Testing Library tests for React Native components.

React Native Testing

Priority: P1 (OPERATIONAL)

Setup

  • Jest: Pre-configured in React Native.
  • Testing Library: Use @testing-library/react-native for user-centric tests.
  • Mocking: Use jest.mock() for native modules.

Component Testing

import { render, fireEvent, waitFor } from '@testing-library/react-native';

test('increments counter on button press', () => {
  const { getByText, getByRole } = render(<Counter />);
  const button = getByRole('button', { name: /increment/i });

  fireEvent.press(button);

  expect(getByText('Count: 1')).toBeTruthy();
});

Async Testing

test('fetches and displays data', async () => {
  const { findByText } = render(<DataComponent />);
  const element = await findByText(/loaded data/i);
  expect(element).toBeTruthy();
});

Best Practices

  • User-Centric: Use getByRole, getByText over testID when possible.
  • Integration > Unit: Test features, not implementation.
  • Avoid Snapshots: Use sparingly. Brittle and hard to review.
  • Coverage: Aim for 70%+. Focus on critical paths.

Anti-Patterns

  • No Testing Implementation: Test behavior, not internals.
  • No testID Overuse: Prefer accessible queries.

References

See references/testing-library.md for RNTL setup, mocking providers, and integration flow examples.