I want to check if inside my component exists a button.
import React, {useState} from 'react';
const Text = ({text}) => {
const [state, setState]= useState(0);
const add = () => {
setState(state+1)
};
return (
<div>
<h1>Hello World</h1>
<h2>Hello {text}</h2>
<h2>Count {state}</h2>
<button role="button" onClick={add}>Increase</button>
</div>
);
};
export default Text;
For that test i created:
test('check counter', ()=> {
const { getByText } = render(<Text />);
const button = getByText("Increase");
expect(button.toBeTruthy())
});
After running the test i get TypeError: button.toBeTruthy is not a function.
Why this errror appears and how to solve the issue?