How to jest.mock a client component imported into a Server component?
Unanswered
Philippine Crocodile posted this in #help-forum
Philippine CrocodileOP
Hey everyone - I have a server component that renders a client component form in certain conditions and I want to be able to test it effectively using Jest and RTL. However I'm struggling to figure out how to either get RTL to render the child client component which relies on a provider wrapper, or mocking the child client component. I am using the App router
e.g. when I try this:
I get this error when I run the test:
- I've tried variations of
Any pointers?
e.g. when I try this:
jest.mock('./components/vendor-email-form', () => ({
__esModule: true,
default: jest.fn(({ userId }) => <div>VendorEmailForm for {userId}</div>),
}));I get this error when I run the test:
Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.- I've tried variations of
jest.mock to no avail.Any pointers?
1 Reply
Philippine CrocodileOP
nvm the error was unrelated. ignore me