I want to do unit testing on the Form component. user is context data that is shared with all the children component.
const { user } = useContext(UserContextAPI);
return (
<> {!user ? (
<>
{navigation.push({
pathname: "./Login",
state: { editProduct: "edit" },
})}
</>
) : (
<Form>.....</From>
)
}
</>
);
I have written a simple test case to test form component
it("should contain From component", () => {
let wrapper = mount(
<BrowserRouter>
<EditProduct.WrappedComponent />
</BrowserRouter>
);
expect(wrapper.find("Form").exist()).toEqual(true);
});
But the test case failed I think based on conditional rendering it doesn't go to test the Form component. How could we do the conditional rendering based on the context data?