最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - When using react-query, how to write unit tests for the scenario of Dependent Queries? - Stack Overflow

programmeradmin2浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论