Here we will see how to test Checkbox using Jest.
function App() {
return (
<div className="App">
<input type="checkbox" checked={true}/>
</div>
);
}
export default App;
test('Check Initial Conditions', () => {
render(<App />)
const checkbox = screen.getByRole('checkbox')
expect(checkbox).toBeChecked()
})
npm test
function App() {
return (
<div className="App">
<input type="checkbox"/>
</div>
);
}
export default App;
test('Check Initial Conditions', () => {
render(<App />)
const checkbox = screen.getByRole('checkbox')
expect(checkbox).not.toBeChecked()
})
npm test