> react-native-testing
Jest and React Native Testing Library for component and integration tests. 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)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/react-native-testing?format=md"React Native Testing
Priority: P1 (OPERATIONAL)
Setup
- Jest: Pre-configured in React Native.
- Testing Library: Use
@testing-library/react-nativefor 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,getByTextovertestIDwhen 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.
Reference & Examples
See references/testing-library.md for RNTL Setup, Mocking Providers, and Integration Flow examples.
Related Topics
common/quality-assurance | react/testing
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)