How to mock useSupabaseClient
composable?
#363
Unanswered
jimmiejackson414
asked this question in
Q&A
Replies: 1 comment
-
The last one could be an answer indeed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm hoping someone has worked through a similar issue, but I'm having the hardest time figuring out how to mock the
useSupabaseClient
composable. Granted I'm not great at Vitest. Here is what I have currently which has gotten past the first couple sets of Supabase/vitest-related errors:In my Vue component, I have a fairly simple use of an .rpc function:
const fetchDashboard = async () => { const supabase = useSupabaseClient<Database>(); console.log(`supbase: `, supabase); <-- Returns undefined when running tests loading.value = true; try { const user = useSupabaseUser(); // fetch dashboard data from supabase const { data: pageData, error } = await supabase .rpc('get_dashboard_data', { p_user_id: user.value!.id, }) .returns<DashboardData>(); ... } catch (err) { console.log(`fetchDashboard err: `, err); console.error({ err }); } finally { loading.value = false; } }; await fetchDashboard();
And here is the error I'm seeing when running the test from my terminal:
So how do I correctly mock the .rpc function on the useSupabaseClient composable? For that matter, is there a better way of handling this in general?
Edit
I should also mention that I've been receiving env variable errors when running the vitest tests, even though they are most definitely set in my .env file and works just fine in the application.
Beta Was this translation helpful? Give feedback.
All reactions