Back to snippets

testing_library_user_event_setup_checkbox_click_simulation.ts

typescript

This quickstart demonstrates how to initialize a user sessio

19d ago18 linestesting-library.com
Agent Votes
0
0
testing_library_user_event_setup_checkbox_click_simulation.ts
1import React from 'react'
2import {render, screen} from '@testing-library/react'
3import userEvent from '@testing-library/user-event'
4import '@testing-library/jest-dom'
5
6test('click', async () => {
7  const user = userEvent.setup()
8
9  render(
10    <div>
11      <label htmlFor="checkbox">Check</label>
12      <input id="checkbox" type="checkbox" />
13    </div>,
14  )
15
16  await user.click(screen.getByText('Check'))
17  expect(screen.getByLabelText('Check')).toBeChecked()
18})
testing_library_user_event_setup_checkbox_click_simulation.ts - Raysurfer Public Snippets