I'm writing a test case for the Increment button when it is clicked.
function App() {
const [count, setCount] = useState(0);
const handleIncrement = () => {
if(count >= 0){
setCount(count + 1);
}
}
const handleDecrement = () => {
if(count > 0){
setCount(count - 1);
}
}
return (
<div>
Count : {count}
</div>
<div>
<button onClick={handleIncrement}>Increment</button>
<button onClick={handleDecrement}>Decrement</button>
</div>
</div>
);
}
Below is the test case that gives me error saying Matcher error: received value must be a mock or spy function
How to expect the button is clicked when the click event is fired. Could anyone please help?
it('should handle count increment', ()=>{
render(<App />);
const incrementButton = screen.getByRole('button',{name: 'Increment'})
fireEvent.click(incrementButton)
expect(incrementButton).toHaveBeenCalled()
})