tRPCttRPC
Powered by
ZephZ
tRPC•4y ago•
1 reply
Zeph

Testing with React Testing Library

Hi! I am trying to test my
DestinationForm
DestinationForm
component using react testing library.
My test is simply rendering the component:
test('contains 2 input fields and a submit button', () => {
  const view = render(<DestinationForm />)
})
test('contains 2 input fields and a submit button', () => {
  const view = render(<DestinationForm />)
})

But I get this error:
TypeError: Cannot destructure property 'client' of 'useContext(...)' as it is null.
const { mutateAsync, error, isLoading } = trpc.itinerary.create.useMutation()
TypeError: Cannot destructure property 'client' of 'useContext(...)' as it is null.
const { mutateAsync, error, isLoading } = trpc.itinerary.create.useMutation()

My guess is that I have to somehow wrap the DestinationForm component with some context so that it is aware of the query client but I'm not sure how to.
I'm super new to testing so any help is appreciated(:

Thank you!
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Examples of Vitest with React Testing Library
Daniel SDDaniel S / ❓-help
3y ago
Test example for react-testing-library
lukasLlukas / ❓-help
4y ago
CreateCaller with React-query
lunacraftsLlunacrafts / ❓-help
2y ago