itsravenous
Typing a shared TRPC provider for testing
Context:
- We have a monorepo with several micro-frontends which use Next.
- We're moving to using tRPC to communicate between the front end and Next backend
- We test our components with React Testing Library
- We have a shared package for our testing utils, including a render method that renders a component for testing with all required providers (Theme, i18n, etc etc)
Problem:
We want to add a tRPC provider to the providers that our custom render method wraps around the component under test, so that components that use tRPC queries/mutations can be tested with RTL. The basic idea is something like this:
but TypeScript complains about
testTRPC.createClient
:
and testTRPC.Provider
:
I'm guessing the usage of AnyRouter
is the problem here, but really not sure what type I can provide here, since it could be the AppRouter
from any one of our micro-frontends - perhaps something using generics?9 replies