How I solved Supabase's chainable query builder problem in React Native tests
Every React Native + Supabase tutorial ends the same way. The app works in the simulator. Tests are left as an exercise for the reader. This one is different. I recently published react-native-expo...

Source: DEV Community
Every React Native + Supabase tutorial ends the same way. The app works in the simulator. Tests are left as an exercise for the reader. This one is different. I recently published react-native-expo-supabase-starter, a production-ready starter extracted from ReptiDex, a mobile app I built and launched solo. 50 paid subscribers and 200 animals tracked within 9 days of launch. The starter includes the full auth flow, a RevenueCat subscription system, TanStack Query, and Zustand. But the part most people ask about is the testing setup. Specifically: how do you actually test Supabase queries in Jest without a running database or a fake HTTP server? Here's the problem and how I solved it. The Problem Supabase queries are fluent chains: const { data, error } = await supabase .from('profiles') .select('*') .eq('id', userId) .single() A naive jest.mock('@supabase/supabase-js') breaks because each method in the chain returns a new object. The mock returns undefined partway down the chain and you