I'm looking at the answers here: How to unit test a method of react component?
I'm trying to use a components private function in one of my jest tests but when I do the following:
const nPanel = shallow(<NotificationsPanel />);
nPanel.dive().instance().openPanel(true);
But I get an error in my IDE (and when i run the test):
Property 'openPanel' does not exist on type 'Component<{}, {}, any>'
Which it definitely doesn't. I'm using Typescript so do I need to type the instance or something? NotificationsPanel isn't a type so I cant do as NotificationsPanel.
I'm not sure where to go from here with it.
Here is the openPanel code:
const openPanel = useCallback((openState: boolean) =>
{
setOpen((previousValue) =>
{
if (openState != null)
{
return openState;
}
else
{
return !previousValue;
}
});
setOpenedDateTime(Date.now());
}, []);