android-logo

Jest Checkbox Testing

Table of Content

  • Test Checkbox Checked
  • Test Checkbox Un-checked

Here we will see how to test Checkbox using Jest.


Test Checkbox Checked

App.js file


function App() {

    return (
      <div className="App">
        <input type="checkbox" checked={true}/>
      </div>
    );
  }
  
export default App;

App.test.js file


test('Check Initial Conditions', () => {
    render(<App />)
  
    const checkbox = screen.getByRole('checkbox')
    expect(checkbox).toBeChecked()
  })

To Run test we use below command


npm test

jest-test

Test Checkbox Un-checked

App.js file


function App() {

    return (
      <div className="App">
        <input type="checkbox"/>
      </div>
    );
  }
  
  export default App;

App.test.js file


test('Check Initial Conditions', () => {
    render(<App />)
  
    const checkbox = screen.getByRole('checkbox')
    expect(checkbox).not.toBeChecked()
  })

To Run test we use below command


npm test

jest-test

previous-button
next-button

facebook-logo
twitter-logo
instagram-logo

2020 © All rights reserved.