I have a Custom Hook like below
const useSum = (a = 1, b = 1) => {
const [sum, setSum] = useState(a + b);
useEffect(() => {
setSum(a + b);
}, [a, b]);
return sum;
}
I am using this in my funcionat component
const MyFuncComp = () => {
const sum = useSum(1, 2);
return (
<div>{sum}</div>
);
}
In test case I have it like this
describe('Testing MyFuncComp', () => {
const myFuncComp = mount(<MyFuncComp />);
it('should have value of sum', () => {
const expected = '3';
const received = myFuncComp.find('div').text();
expect(received).toEqual(expected);
});
})
It's never executing 'useState' or 'useEffect'. Received value is always 'undefined';