I have the following code and trying to test handleChange function with jest. But it seems that App.prototype is undefined. Can someone help me?
import React, {useState, useEffect} from 'react';
const App = () => {
const handleChange = () => {
....
}
return (
<div className="btn" data-testid='button' type="button"
onClick={handleChange}><span>Add</span></div>
);
}
Test Code
test('call handleChange function', () => {
const spy = jest.spyOn(App.prototype, "handleChange")
const { getByTestId } = render(<App />);
fireEvent.click (getByTestId('button') );
const button = getByTestId('button')
expect(spy).toHaveBeenCalled();
})