← ClaudeAtlas

rn-testinglisted

Testing patterns for React Native with Jest and React Native Testing Library. Use when writing tests, mocking Expo modules, testing Zustand stores, or debugging test failures.
aiskillstore/marketplace · ★ 329 · Testing & QA · score 79
Install: claude install-skill aiskillstore/marketplace
# React Native Testing ## Problem Statement React Native testing requires extensive mocking of native modules, careful handling of async operations, and understanding of Zustand store testing patterns. This codebase has 30+ test files with established patterns. --- ## Pattern: Zustand Store Testing **Problem:** Store state persists between tests, causing flaky tests. ```typescript import { useAssessmentStore } from '@/stores/assessmentStore'; const initialState = { userAnswers: {}, completedAssessmentAnswers: {}, retakeAreas: new Set<string>(), loading: false, }; describe('Assessment Store', () => { // Reset store before each test beforeEach(() => { useAssessmentStore.setState(initialState, true); // true = replace entire state }); it('saves answer to store', async () => { const store = useAssessmentStore.getState(); await store.saveAnswer('q1', 4); expect(useAssessmentStore.getState().userAnswers['q1']).toBe(4); }); it('enables retake for skill area', async () => { const store = useAssessmentStore.getState(); await store.enableSkillAreaRetake('fundamentals'); expect(useAssessmentStore.getState().retakeAreas.has('fundamentals')).toBe(true); }); }); ``` **Key points:** - Use `setState(initialState, true)` to replace (not merge) state - Get fresh state with `getState()` after async operations - Don't rely on component re-renders in store tests --- ## Pattern: Async Store Operations **Problem:**