Let's say I have this simple React (TypeScript) component:
function Header(): JSX.Element {
const initialItemIndex = useInitialItemIndex();
const [currentItem, setCurrentItem] = useState(initialItemIndex);
function onChangeFunc(event: Event, itemNum: number): void {
setCurrentItem(itemNum);
}
return (
<div>
<Tabs value={currentTab} onChange={onChangeFunc}>
<Tab label="A" />
<Tab label="B" />
</Tabs>
</div>
);
}
I want to test (Jest, TypeScript) that the Tabs.onChange
is calling the onChangeFunc
. How should I test it? Something like:
const wrapper = shallow(<Header />);
const spyFunc = jest.spyOn(Header, 'onChangeFunc');
wrapper.find('Tabs').simulate('change');
expect(spyFunc).toBeCalled();
I'm getting error, about the second parameter in the spyOn:
TS2345: Argument of type '"onChangeFunc"' is not assignable to parameter of type 'never'.
What am I doing wrong?