how to write unit tests for useUpdateTodo hook without mock useGetUserId
// Get the user
const useGetUserId = ()=>{
const { data: user } = useQuery({
queryKey: ['user', email],
queryFn: getUserByEmail,
})
return user?.id
}
// Then update
const useUpdateTodo = ()=>{
const userId = useGetUserId()
const mutation = useMutation({
mutationFn: (newTodo) => {
return axios.post('/todos', newTodo, userId)
},
})
return mutation
}
I use react-hooks-testing-library,According to the normal usage of renderHook, when invoking the mutation through result.current, it does not wait for the result returned by useGetUserId.